kjv
kjv

Reputation: 11337

Single assembly from multiple projects

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#.

Upvotes: 9

Views: 12915

Answers (3)

achakravarty
achakravarty

Reputation: 408

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.

Upvotes: 1

Fredrik Mörk
Fredrik Mörk

Reputation: 158389

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.

Upvotes: 1

Andrew Hare
Andrew Hare

Reputation: 351748

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.

Upvotes: 14

Related Questions