Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

.net - Visual Studio 2008: Creating Single DLL from Solution with Many Projects

I have an ASP.NET web application developed in Visual Studio 2008, composed of 3 different projects (one for UI, one of BO and the third for DAL).

How can I generate a single assembly file which holds all 3? Now it's generating 3 DLLS each for each project in the solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For each of your projects create a netmodule or an assembly and compile/merge them all into a single assembly.

First alternative. This was proposed by Jay R. Wren:

This is a cute hack, but with the CSC and VBC both supporting the /target:module and /addmodule options, you could actually do this without ILMerge just by using a shell script or make file.

Visual Studio doesn't support the "netmodule" type, but MSBuild does.

Add the VB project to your solution. Unload the project and edit the project file.

Change OutputType to module:

<OutputType>module</OutputType>

Instead of adding a reference to the desired project, we add a module. Sadly, again VStudio fails here, but MSBUILD works just fine. Unload the project and edit the project file. Add an item group with AddModules include directives.

<ItemGroup><AddModules Include="..VbXmlinDebugVbXml.netmodule" /></ItemGroup>

This will tell msbuild to tell CSC to use /addmodule directives, just like the Reference Item Group which Studio does manage.

Major Drawback: No Visual Studio Intellisense for the added module. We already have references, it is too bad we don't have modules. [UPDATE: As @Ark-kun pointed out elsewhere, Visual Studio can reference .netmodule projects and have Intellisense. Just add the project reference BEFORE changing the output type.]

SharpDevelop has the first step, but the second step, an "Add Module" gui has been open as a low priority item since SD 2.0.

Second way. This great article (by Scott Hanselman) describes how to megre assemblies automatically if you're using Visual Studio. It does give you IntelliSense support , unlike the first alternative.

Third way. Do it manually with scs.
Example how to create several modules and link theme into a single dll:

csc /t:module RarelyUsedTypes.cs
csc /out:AllTypes.dll /t:library /addmodule:RarelyUsedTypes.netmodule AllTypes.cs

For more information see Richter's book CLR via C#.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...