ILMerge Best Practices

前端 未结 12 2175
闹比i
闹比i 2020-11-28 20:19

Do you use ILMerge? Do you use ILMerge to merge multiple assemblies to ease deployment of dll\'s? Have you found problems with deployment/versioning in production after ILMe

12条回答
  •  迷失自我
    2020-11-28 20:38

    Introduction

    This post shows how to replace all .exe + .dll files with a single combined .exe. It also keeps the debugging .pdb file intact.

    For Console Apps

    Here is the basic Post Build String for Visual Studio 2010 SP1, using .NET 4.0. I am building a console .exe with all of the sub-.dll files included in it.

    "$(SolutionDir)ILMerge\ILMerge.exe" /out:"$(TargetDir)$(TargetName).all.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards
    

    Basic hints

    • The output is a file "AssemblyName.all.exe" which combines all sub-dlls into one .exe.
    • Notice the ILMerge\ directory. You need to either copy the ILMerge utility into your solution directory (so you can distribute the source without having to worry about documenting the install of ILMerge), or change the this path to point to where ILMerge.exe resides.

    Advanced hints

    If you have problems with it not working, turn on Output, and select Show output from: Build. Check the exact command that Visual Studio actually generated, and check for errors.

    Sample Build Script

    This script replaces all .exe + .dll files with a single combined .exe. It also keeps the debugging .pdb file intact.

    To use, paste this into your Post Build step, under the Build Events tab in a C# project, and make sure you adjust the path in the first line to point to ILMerge.exe:

    rem Create a single .exe that combines the root .exe and all subassemblies.
    "$(SolutionDir)ILMerge\ILMerge.exe" /out:"$(TargetDir)$(TargetName).all.exe" "$(TargetDir)$(TargetName).exe" "$(TargetDir)*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards
    rem Remove all subassemblies.
    del *.dll
    rem Remove all .pdb files (except the new, combined pdb we just created).
    ren "$(TargetDir)$(TargetName).all.pdb" "$(TargetName).all.pdb.temp"
    del *.pdb
    ren "$(TargetDir)$(TargetName).all.pdb.temp" "$(TargetName).all.pdb"
    rem Delete the original, non-combined .exe.
    del "$(TargetDir)$(TargetName).exe"
    rem Rename the combined .exe and .pdb to the original project name we started with.
    ren "$(TargetDir)$(TargetName).all.pdb" "$(TargetName).pdb"
    ren "$(TargetDir)$(TargetName).all.exe" "$(TargetName).exe"
    exit 0
    

提交回复
热议问题