visual-studio - 何时以及如何将 ILMerge 与 Visual Studio 项目/解决方案一起使用

标签 visual-studio build-process ilmerge

我正在开发一个中型企业应用程序。
有很多项目/解决方案。
例如:

  • 公司数据
  • Company.Data.LinqToSql
  • Company.Entities(业务对象)
  • 公司.BLL

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

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

    这是我应该使用 ILMerge 的地方吗?创建一个程序集...例如Company.dll?

    我将如何将其集成到我的构建过程中?

    最佳答案

    问题ILMerge Best Practices
    有关于原因的好信息。

    当我使用 ILMerge 时,我使用它来构建单个 DLL,以简化部署。

    至于如何,我定义了一个单独的自定义 VS 项目,如果您愿意的话,“Converged.csproj”。在那个 .csproj 文件中,我定义了一个自定义 Compile 目标。它是样板代码,对项目的所有引用程序集执行 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>
    

    关于visual-studio - 何时以及如何将 ILMerge 与 Visual Studio 项目/解决方案一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1561566/

    相关文章:

    .net - 尽管日志输出没有报告错误,但 ILMerge 生成的程序集无法运行 - 这是为什么?

    c# - 在编写代码时,确定类型是否为 IDisposable 的最快方法是什么

    c# - context.SaveChanges 不会保存更改而不会出现任何错误

    java - Maven 模块 + 构建单个特定模块

    visual-studio-2008 - 使用 Visual Studio 进行跨平台开发的最佳方法是什么?

    c# - 尝试合并 pdb 文件时出现 ILMerge 异常

    c# - 如何在visual studio中添加资源文件

    c++ - 在 Windows 7 上静态构建 Qt 5.1.1 - nmake 和 cl 错误

    PHP7 和 Apache 编译警告

    c# - ILMerge - "Unresolved assembly reference not allowed",包文件夹中的 RestSharp Nuget 包