当 &如何将 ILMerge 与 Visual Studio 项目/解决方案结合使用

发布于 2024-08-07 10:02:30 字数 344 浏览 8 评论 0原文

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

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

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

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

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

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

I'm developing a medium sized enterprise application.
There are many projects / solutions to this.
For example:

  • Company.Data
    • Company.Data.LinqToSql
  • Company.Entities (business objects)
  • Company.BLL

I then have some applications - for example a windows service:
MyWindowsService.

When i deploy this (by creating a setup project) it installs a load of DLL's from the output of the above mentioned projects.

Is this where i should be using ILMerge? to create one assembly.... Company.dll for example?

How would i go about integrating this into my build process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兲鉂ぱ嘚淚 2024-08-14 10:02:30

问题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 -> '"%(Fullpath)"', ' ')" />
  <!-- 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=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe"  /t:library  /xmldocs /out:"$(IntermediateOutputPath)$(TargetFileName)"  @(AssembliesToMerge -> '"%(Fullpath)"', ' ') " />

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

The question ILMerge Best Practices
has good info on why.

When I use ILMerge, I use it to build a single DLL, to simplify deployment.

As to How, I define a separate, custom VS project, "Converged.csproj" if you like. In that .csproj file I define a custom Compile target. It is boilerplate code, that performs an ILMerge on all the referenced assemblies for the project.

It looks like this:

<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 -> '"%(Fullpath)"', ' ')" />
  <!-- 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=""$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe"  /t:library  /xmldocs /out:"$(IntermediateOutputPath)$(TargetFileName)"  @(AssembliesToMerge -> '"%(Fullpath)"', ' ') " />

  <!-- 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文