我的解决方案是这样的:我将 Ilmerge 目标文件的导入放在 csproj 中,它是这样的:
<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>
然后在安装项目中,我不将我的 exe 作为主要输出包含在内,而是将其包含为一个文件,以及它的本地化资源和内容。
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.