다음을 통해 공유


Netmodules: Sort of like a lib

I first ran into netmodules before VS 2002 was shipped. The netmodule gave me precisely what I asked for, without actually solving my problem.  I wanted to use multiple languages (C#, and C++ /clr) in a single assembly.  It turns out a single assembly can be multi-module.  Multi-module means a single .Net assembly is spread across multiple win32 dlls.  What I really wanted was a single module assembly written in multiple languages. Netmodules couldn't solve my problem back then, but with the VS 2005 C++ linker they can now.

 

Check out JuFeng's articles for some more in depth coverage, and an explanation why you might want a multi-module assembly:

 

MultiModule Assemblies

Netmodule vs. Assembly

 

Since JuFeng's examples didn't show how to create debug info I thought I'd make an updated example here.

Here's a quick example with a multi-module assembly:

a_source

b_source

From the Visual Studio  2005 Command Prompt:

 

C:\blog\linkexample>vbc /target:module /debug+ b.vb

C:\blog\linkexample>csc /debug+ /addmodule:b.netmodule a.cs

C:\blog\linkexample>devenv /debugexe a.exe

Check out the modules window:

multi_module

And the callstack window:

multi2_callstack 

To get a single file assembly I'll need to recompile the cs file into a netmodule then use the c++ linker.

 

C:\blog\linkexample>csc /addmodule:b.netmodule /target:module /debug+ a.cs

C:\blog\linkexample>link /entry:fooCS.Main /out:theone.exe /subsystem:console /debug a.netmodule b.netmodule

C:\blog\linkexample>devenv /debugexe theone.exe

 

Now check out the modules window:

single_module 

And the callstack window:

 single2_callstack

Comments