简体   繁体   English

如何在安装项目中使用IlMerge?

[英]How to use IlMerge in a Setup Project?

I have use IlMerge to merge all the dlls of my projects in one exe. 我使用IlMerge在一个exe中合并我项目的所有dll。 I use a targets file which is referenced in the "import" of the main csproj. 我使用目标文件,该文件在主csproj的“import”中引用。

The ExecCommand in the targets is: 目标中的ExecCommand是:

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

This works. 这有效。

But then I have a Setup Project, when it builds, it ignores the "import" and it doesn't merge the dlls. 但是我有一个安装项目,当它构建时,它忽略了“导入”,它没有合并dll。 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. 我曾尝试在主项目的Post-build事件(在项目的属性中)为Ilmerge编写相同的代码,但它给出了错误代码1。

I'd recommend that you check out the ILMerge Task in the MSBuild Community Tasks . 我建议您查看MSBuild社区任务中的ILMerge 任务 Documentation for the ILMerge Task is included in the download . ILMerge任务的文档包含在下载中 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? 在您的具体问题上,除了错误代码1之外,您是否收到任何其他错误消息? Comment, and I'll edit my response as best I can. 评论,我会尽我所能编辑我的回复。

My solution has been this: I put the import in csproj for the Ilmerge targets file which is this: 我的解决方案是这样的:我把导入在csproj中用于Ilmerge目标文件,这是:

<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>

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. 然后在安装项目中,我不包括我的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. 我认为这是有效的,但遗憾的是,在将它打包到setup exe之前,我无法执行我的应用程序的postbuild事件(ilmerge进程)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM