当&如何使用ILMerge与Visual Studio项目/解决方案(When & How to u

2019-08-17 23:56发布

我正在开发一个中等规模的企业应用程序。 有这许多项目/解决方案。 例如:

  • Company.Data
    • Company.Data.LinqToSql
  • Company.Entities(业务对象)
  • Company.BLL

然后,我有一些应用程序 - 例如Windows服务:MyWindowsService。

当我部署此(通过创建一个安装项目),从上述项目的输出安装DLL的的负载。

这是我应该使用ILMerge? 创建一个装配.... Company.dll例如?

我将如何去了解这个集成到编译过程中?

Answer 1:

问题ILMerge最佳实践对为什么好的信息。

当我使用ILMerge,我用它来建立一个DLL,以简化部署。

至于如何定义一个单独的,自定义VS项目,“Converged.csproj”如果你喜欢。 在这种.csproj的文件,我定义自定义编译目标。 这是样板代码,上项目的所有引用的程序集执行ILMerge。

它看起来像这样:

<Target Name="Compile">
  <!-- Outputs="$(IntermediateOutputPath)$(TargetFileName)" -->
  <!-- Outputs="$(TargetPath)" -->
  <Message Text="Performing the Ilmerge." />
  <!-- in this CreateItem stanza, we collect all the DLLs for the referenced projects -->
  <CreateItem Include="@(_ResolvedProjectReferencePaths)">
    <Output TaskParameter="Include" ItemName="AssembliesToMerge" />
  </CreateItem>
  <!-- This weird bit of hieroglyphics is the assemblies to merge, quoted, and separated by spaces -->
  <!-- Example:  "c:\foo\project1\bin\Debug\ProjectOne.dll"   "c:\foo\project2\bin\Debug\ProjectTwo.dll"  -->
  <Message Text="AssembliesToMerge= @(AssembliesToMerge -> '&quot;%(Fullpath)&quot;', ' ')" />
  <!-- Message Text="TargetPath= $(TargetPath)" / -->
  <Message Text="TargetFileName= $(TargetFileName)" />
  <!-- produce the merged assembly - putting the output in the "IntermediateOutputPath" eg obj\Debug. -->
  <!-- it will be copied later by the CopyFilestoOutputDirectory task defined in Microsoft.Common.Targets -->

  <Error
     Text="ILMerge cannot be found. You need to download and install ILMerge in order to build DotNetZip."
     Condition="!Exists('$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe')" />

  <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot;  /t:library  /xmldocs /out:&quot;$(IntermediateOutputPath)$(TargetFileName)&quot;  @(AssembliesToMerge -> '&quot;%(Fullpath)&quot;', ' ') " />

  <!-- for some reason the XML doc file does not get copied automatically from obj\Debug to bin\Debug. -->
  <!-- we do it here explicitly. -->
  <Copy SourceFiles="$(IntermediateOutputPath)$(AssemblyName).XML" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)" />
</Target>


文章来源: When & How to use ILMerge with Visual Studio Project / Solution