How to use IlMerge in an installation project?

I have IlMerge to combine all the dlls of my projects into one exe. I am using a targets file referenced by the "import" of the main csproj.

ExecCommand in order to:

  <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(IlmergeAssemblies->'&quot;%(FullPath)&quot;', ' ')" /> 

It works.

But then I have an installation project, when it builds, it ignores the “import” and does not merge the DLL. How can I use the goals file in the installation project?

I tried writing the same code for Ilmerge in the Post-build event (in the project properties) of the main project, but it gives me error code 1.

+3
source share
2 answers

My solution was this: I put the import in csproj for the Ilmerge targets file, which:

<Project 
 DefaultTargets="Build" 
 xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

 <Target Name="AfterBuild">
   <CreateItem Include="@(ReferencePath)" Condition="'%(CopyLocal)'=='true'">
       <Output TaskParameter="Include" ItemName="IlmergeAssemblies"/>
   </CreateItem>

   <Message Text="MERGING: @(IlmergeAssemblies->'%(Filename)')" Importance="High" /> 

  <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(IlmergeAssemblies->'&quot;%(FullPath)&quot;', ' ') /log:ILMerge.log" /> 

 </Target>

 <Target Name="_CopyFilesMarkedCopyLocal"/>

</Project>

exe , .

, , , postbuild ( ilmerge), setup exe.

+1

ILMerge MSBuild. ILMerge . , .

, 1, - ? , .

+2

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


All Articles