Single assembly from multiple projects

落爺英雄遲暮 提交于 2019-12-21 16:38:40

问题


In a .net application involving several projects in one solution, I have a project with the namespace set to Company.Product.UI and another one with Company.Product.UI.WebPages. My problem is that two dlls result from building the two projects. How can I have a single dll and still preserve the current solution structure. I use Visual Studio 2008 and C#.


回答1:


You will have to either merge the two projects into one project or use a tool like ILMerge to merge the resulting assemblies into a single assembly.

ILMerge is a utility that can be used to merge multiple .NET assemblies into a single assembly. It is freely available for use from the Tools & Utilities page at the Microsoft .NET Framework Developer Center.

If you want to automate ILMerge as an MSBuild task then I would suggest you take a look at ilmerge-tasks:

Interested in using ILMerge during an automated build? ILMerge Tasks containts two buildable projects that will allow you to access ILMerge as a task from both MSBuild and NAnt. It even includes a post-build event that merges ILMerge and the task dll so that you can use the task without ILMerge.exe being present.




回答2:


I guess that you could create a new project file which contains all files from the two projects. That way you can keep the current structure for development, and use the merged project file to build the output to be released from the project. The project files are fairly straightforward xml files, so if you open one of then in a text editor you will probably figure out how they work rather quickly.

The obvious downside with this approach is of course that you will need to maintain this third project file when files are added or removed in one of the projects, but if that is something that does not happen very often it could work rather well, I think.




回答3:


There is simple way to do this, but it may not be the best way. Create a new solution with the name of the dll that you want. Create the folder structure in this project which is the same as the names of the two projects. Then on the specific folder, do an 'Add existing item'. Add the cs files in the project of that name. When you are adding the files, select 'Add as Link' on the Add button (there is a drop down where you can select next to the add button). Keep doing that and build. You will have the dll.

eg. If you have one project called A and one called B and you want to merge them into a a dll called C. Create a new project called C. Add a folder in this project called A and another folder called B. Now say project A has a cs file X.cs and B has one called Y.cs. On the folder called A, right click and do Add existing item. Go to Project A and select X.cs. Next to the Add button, you will see a down arrow. Click that and select Add as link. Do the same for B. Build this project and you will get you dll in the bin folder.



来源:https://stackoverflow.com/questions/893267/single-assembly-from-multiple-projects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!