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 ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.