O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

F.6. Referencing an external module during compilation of an assembly

You have seen how to use the /reference:AssemblyName.dll option of csc.exe to reference an assembly. What happens if the method or class you want to use is not in an assembly, but in a module instead? You cannot reference a module which is not in the same assembly, but you can add that module in the new assembly you are generating during compilation.

Here's an example. It will compile MyMath.cs into a module instead of an assembly.

1: // MyMath.cs
2: public class MyMath{
3:   public static int Triple(int a){
4:     return a*3;
5:   }
6: }

The following command generates MyMath.netmodule:

c:\expt>csc /target:module MyMath.cs

Another class, MyClass.cs, invokes the static method in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required