views:

666

answers:

2

I need to create a .NET assembly composed of 2 modules: 1 internal (in the DLL) with native code and 1 external (in a .netmodule file).

This would be easy to do, except for the native part.

C#'s compiler can do this (this is what I want, but with native code):

csc /t:library /out:foobar.dll foo.cs /out:bar.netmodule bar.cs
-foobar.dll (contains assembly manifest and foo's IL)
    -internal module foobar.dll (contains foo's IL)
    -external module bar.netmodule (contains bar's IL)

C++ compiler/linker will put everything in 1 internal module.

cl /clr /LD foo.cpp /link bar.netmodule /LTCG
OR link /out:foobar.dll foo.netmodule bar.netmodule
-foo(bar).dll (contains IL for both foo and bar, as well as assembly manifest)

Assembly Linker only does external modules:

al /out:foobar.dll foo.netmodule bar.netmodule
-foobar.dll (only contains manifest)
    -external module foo.netmodule (contains foo's IL)
    -external module bar.netmodule (contains bar's IL)

I've also tried tweaking the IL manually, but ILDASM and ILASM don't appear able to round-trip the native code:

ildasm foobar.dll /out=foobar.il
ilasm /dll foobar.il
-lots of errors


For clarification, what I want is this:

-foobar.dll (contains assembly manifest and foo's IL AND NATIVE CODE)
    -internal module foobar.dll (contains foo's IL AND NATIVE CODE)
    -external module bar.netmodule (contains bar's IL)
+1  A: 

Henk is already on the right track. You can create a .netmodule for input for creating assemblies only. An assembly is the smallest executing unit in the .NET environment. An assembly can consist of one or more physical files. It can contain several resources: resource files, netmodules and native DLLs. A netmodule cannot be deployed by itself, it must be linked into an assembly.

Now that we have that out of the way, let's try to focus on what you're after. Are you trying to create a multi-file assembly? That's possible. Here's a rather old but still useful post on multi-module assemblies. Or are you trying to create netmodules that can be used as libraries? Because that is not possible, because netmodules do not contain an assembly.

If this doesn't answer your question, can you explain in a bit more detail what you want the end result to be and/or how you expect it to be used?

Abel
"Multi-file assembly" is in the title of the question; "deploy modules individually is not."I know I can link multiple .netmodules into a single-file assembly: the cl.exe and link.exe examples do that.I know I can create a 3-file, 2-module assembly: al.exe does that.I know I can make a 2-file, 2-module assembly: the csc.exe example does that. This is what I want, but with C++/CLI.
pyrochild
A: 

Disclaimer: This is untested.

Are you looking for the correct cl compiler option?

cl /clr:pure /LN Stringer.cpp
cl /clr:pure Client.cpp /link /ASSEMBLYMODULE:Stringer.netmodule

I'm surprised the link.exe tool in the link provided by Abel didn't work for you.

Ryan Riley