8

I have a base project that feeds two different projects. I want to be able to have the primary project compile all the references into one dll at compile time.

This needs to be something that is built into the project build so that Jr developers don't have to worry about it.


Solution: I ended up adding a line to the Post-build action of the project, so that a good build does the following:

$(ProjectDir)ilmerge.exe /out: /ver: <.dll> <.dll>

ilmerge.exe was moved to the project and the above line takes the dlls given and creates one.

Joel Coehoorn
  • 362,140
  • 107
  • 528
  • 764
Omnia9
  • 1,533
  • 3
  • 14
  • 38
  • 2
    OK, so what's your question? You've tagged ilmerge, which is a tool that you can use to do this. Do you have a question about that? – FishBasketGordo Aug 04 '11 at 13:07
  • http://stackoverflow.com/questions/1829531/how-do-i-merge-multiple-net-assemblies-into-a-single-assembly – Damith Aug 04 '11 at 13:12
  • Sorry, I know how to use the tool with NuGenUnify, but I want it to happen when i Compile the project. Can I add to that process? – Omnia9 Aug 04 '11 at 14:35
  • That wasn't directly clear from your question, maybe you could update it. I edited my answer. – Abel Aug 04 '11 at 21:53
  • possible duplicate of [one DLL, multiple projects?](http://stackoverflow.com/questions/2016722/one-dll-multiple-projects) – Cheng Chen Apr 17 '13 at 09:43
  • @Abel: I have VS installed (2015 Enterprise) and there is nothing (executable, folder, etc.) anywhere in my filesystem named "ILMerge" – Bob Sammers Jul 13 '16 at 15:16
  • @BobSammers ilmerge is not part of VS. There is a nuget package that is used. https://www.nuget.org/packages/ilmerge – Omnia9 Jul 14 '16 at 13:34
  • @Arnej65 "ILMerge is not part of VS": that was my point! But I didn't know it was available as a nuget package. That's useful info. – Bob Sammers Jul 14 '16 at 15:02
  • @BobSammers, the other commenters are right (I've removed mine, it was incorrect). I thought it was part of VS or the .NET SDK, but can't find that either. Apparently it used to be a [separate download until 2012](https://www.microsoft.com/en-us/download/details.aspx?id=17630). The [NuGet package](https://www.nuget.org/packages/ilmerge) is the best way to get it presently. You may also be interested in [ILMerge GUI](https://ilmergegui.codeplex.com/) from CodePlex, which provides a GUI interface to ILMerge. Its development was interrupted, but is now active again. I will update my answer too. – Abel Jul 18 '16 at 11:47

3 Answers3

10

(this answer was edited to update links to new download locations and to reflect new insights)

Your best bet is to use Micorosoft's ILMerge. It used to be available as a separate download from Microsoft Research (it is not part of VS or the .NET SDK).

The original version was maintained until 2012. It is now a NuGet package, which is the best way to get it presently, and to add it to your project and build server.

As an alternative, you may want to try ILMerge GUI from CodePlex, which provides a GUI interface to ILMerge. Its development was interrupted, but is now active again.

A Codeproject article on ILMerge explains more on how to use it and explains some use-case. An example command is:

ilmerge /target:winexe /out:AllInOne.exe NormalProgram.exe Lib1.dll Lib2.dll

As an alternative, you can use Fody with Costura.Fody, as explained in this SO response.


Note (1): if you need to merge side-by-side assemblies (i.e., mix native 64 bit and 32 bit assemblies), you should consult this SO article on loading side-by-side assemblies dynamically.

Note (2): to add this as an integral step to your build process, just go to Project Properties > Build Events > click "Edit Post-build" and fill in the command from above. Click "Macros" to see how to reference the current file or assembly.

Community
  • 1
  • 1
Abel
  • 52,738
  • 19
  • 137
  • 227
2

Have a look for the external tool ILMerge from Microsoft: http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx It can merge multiple assemblies into just one.

Sebastian P.R. Gingter
  • 5,630
  • 3
  • 26
  • 67
1

You can use ILMerge for merging multiple assemblies:

ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output. See the accompanying documentation for details.

You could merge the base assemblies together and use the resultant assembly as a reference to your other projects.

Alternatively, instead of two projects, have your shared code placed in one project in order to get a single assembly to reference.

Oded
  • 463,167
  • 92
  • 837
  • 979