Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

Question
Is it possible to create assembly which contains two or more .netmodules?
If yes, how to achieve that?
Which tool should I use?

I do not want to reference them, I want to put modules inside assembly.

I already found that there are several tools which are able to link/merge/embed/reference modules into one assembly.
But, none of tools are doing exactly what I want.

Here is what tried already:

I have two source files: L1.cs, E1.cs.
C#
class L1
    {
        public string GetMsg()
        {
            return "Hello, L1 here.";
        }
    }

    public static class E1
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hi, I'm Main!");
            L1 c = new L1();
            Console.WriteLine(c.GetMsg());
        }
    }

With C# compiler, from Visual studio command prompt, I am able to create modules:
C#
> csc -t:module -out:L1.netmodule L1.cs
> csc -t:module -out:E1.netmodule -addModule:L1.netmodule E1.cs


Option 1: Visual C++ Linker
C#
> link -out:MyDll.dll /ltcg /dll *.netmodule 

But, according to manifest there is only one module in assembly MyDll. Source code is there, but there is only one module (maybe I am reading it in wrong way :?)
C#
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly MyDll
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module MyDll.dll
// MVID: {A4FA5CEA-08F8-4A93-BDD3-A2EBD1715B58}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0002       // WINDOWS_GUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x008A0000


Option 2: Assembly Linker
I tried:
C#
al -t:library -out:MyDllAl.dll E1.netmodule L1.netmodule

Results are not what I wanted.
There are more modules, but they are not part of MyDllAl.dll assembly. They are referenced :(.

Option 3: IlMerge, IlRepack
I already used IlMerge - results are disappointing - only one module in assembly.
I haven't tried IlRepack, but according to documentation it's 'clone' of IlMerge (there are few differences, but results are same).
Posted
Comments
[no name] 30-Sep-14 20:39pm    
http://msdn.microsoft.com/en-us/library/k669k83h.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900