Reputation: 7722
I have use IlMerge to merge all the dlls of my projects in one exe. I use a targets file which is referenced in the "import" of the main csproj.
The ExecCommand in the targets is:
<Exec Command=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ')" />
This works.
But then I have a Setup Project, when it builds, it ignores the "import" and it doesn't merge the dlls. How can I use the targets file with the Setup Project?
I have tried writing this same code for Ilmerge in the Post-build event (in properties of the project) of the main project but it gives me error code 1.
Upvotes: 3
Views: 5388
Reputation: 8414
I'd recommend that you check out the ILMerge Task in the MSBuild Community Tasks. Documentation for the ILMerge Task is included in the download. It will take away the complexity of specifying the exact command line arguments as you are doing now.
On your specific issue, other than the error code 1, are you getting any other error message as a result? Comment, and I'll edit my response as best I can.
Upvotes: 2
Reputation: 7722
My solution has been this: I put the import in csproj for the Ilmerge targets file which is this:
<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=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ') /log:ILMerge.log" />
</Target>
<Target Name="_CopyFilesMarkedCopyLocal"/>
</Project>
Then in the setup project i don't include my exe as primary output, i include it as a file, and its localized resources and content.
This works I think, but it is a pity that i couldn't execute the postbuild event of my application (the ilmerge process) before packing it into the setup exe.
Upvotes: 1