using ILMerge with .NET 4 libraries

后端 未结 6 1101
时光取名叫无心
时光取名叫无心 2020-12-02 16:43

Two problems:

1) Basic .NET Assembly Not Included in ILMerged Assembly

I\'m having trouble using ILMerge in my post-build after upgrading fr

6条回答
  •  情书的邮戳
    2020-12-02 17:28

    Here is the "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:"$(SolutionDir)\deploy\$(TargetFileName)" "$(TargetDir)$(TargetFileName)" "$(TargetDir)*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards
    

    Basic hints:

    • Notice the "\deploy\" directory: this is where the output .exe file ends up.
    • Notice the "ILMerge\" directory. I copied the ILMerge utility into my solution directory (so I could distribute the source without having to worry about documenting the install of ILMerge).

    Advanced hints:

    If you have problems with it not working, add an "echo" before the "Post Build" command. Then, open the "Output" window in Visual Studio (View..Output), and check the exact command that Visual Studio actually generated. In my particular case, the exact command was:

    "T:\PhiEngine\CSharp\ILMerge\ILMerge.exe" /out:"T:\PhiEngine\CSharp\Server Side\deploy\NfServiceDataHod.History.exe" "T:\PhiEngine\CSharp\Server Side\NfServiceDataHod\bin\Debug\NfServiceDataHod.History.exe" "T:\PhiEngine\CSharp\Server Side\NfServiceDataHod\bin\Debug\*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards
    

    Update

    Added this to my "Post Build" step, it replaces all .exe + .dll files with a single combined .exe. It also keeps the debugging .pdb file intact:

    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 name we started with.
    ren "$(TargetDir)$(TargetName).all.pdb" "$(TargetName).pdb"
    ren "$(TargetDir)$(TargetName).all.exe" "$(TargetName).exe"
    exit 0
    

提交回复
热议问题