Compile C # project into one dll

I have a base project that supports two different projects. I want the main project to compile all the links into a single dll at compile time.

It should be something that is built into the project assembly so that Jr developers do not have to worry about it.


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

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

ilmerge.exe been ported to the project, and the above line takes the dll data and creates one.

+6
source share
3 answers

(this answer has been edited to update links to new download locations and reflect new ideas)

Best to use Micorosoft ILMerge . It was used as a separate download from Microsoft Research (it is not part of the VS or .NET SDK).

The original version was supported until 2012. Now this is the NuGet Package , which is the best way to get it now, and add it to your project and create a server.

Alternatively, you can try the ILMerge GUI from CodePlex, which provides a GUI interface for ILMerge. Its development was interrupted, but now it is again active.

A Codeproject article on ILMerge explains more about how to use it and explains some use cases. Command example:

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

Alternatively, you can use Fody with Costura.Fody as described in this SO answer .


Note (1): if you need to combine side-by-side assemblies (i.e. mix your own 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 in the assembly process, simply go to "Project Properties"> "Assembly Events"> click "Edit Post-Assembly" and fill out the command above. Click Macros to see how to link to the current file or assembly.

+9
source

Take a look at Microsoft’s external ILMerge tool: http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx It can combine several assemblies with only one.

+1
source

You can use ILMerge to merge multiple assemblies:

ILMerge is a utility for combining multiple .NET assemblies into a single .NET assembly. It works with both executables and DLLs and has several options for controlling the processing and formatting of output. See the accompanying documentation for more details.

You can combine the base assemblies together and use the resulting assembly as a reference to your other projects.

Alternatively, instead of two projects, your common code is placed in one project to get a link to one assembly.

0
source

Source: https://habr.com/ru/post/894281/


All Articles