.net - 如何维护两个独立的项目,但将它们合并到一个 DLL 中?

标签 .net visual-studio ilmerge

我希望我在这里缺少一些简单的东西。我正在尝试维护两个独立的项目

ProjectName.Core &
ProjectName.Infrastructure

这是在典型的洋葱架构中制作的,因此我可以松散地耦合我的服务并获得更大的灵 active 。基础设施项目引用了核心项目。编译后,它们会生成这些 DLL

ProjectName.Core.dll &
ProjectName.Infrastructure.dll

但我想让它只生成 1 个 dll。

ProjectName.Infrastructure.dll (or even ProjectName.dll)

我尝试使用 ILMerge 来执行此操作,但由于基础结构引用了 Core,因此它会抛出异常,因为它找不到 Core dll。它显然没有向内找。

现在我需要维护单独的项目,因为我有一些其他组合引用 Core 和另一个将连接在一起的项目,例如

ProjectName.Core &
ProjectName.DataAccess &
ProjectName.Web

编辑:我当前的解决方案使用 Nant 构建脚本调用 ILMerge。就成功的融合在一起了。但是当我尝试使用合并的 DLL 时,它会抛出异常,因为它找不到核心库。

  <target name="merge.core">
    <property name="temp.dir" value="${build.dir}\Temp\"/>
    <mkdir dir="${temp.dir}" if="${not directory::exists(temp.dir)}"/>
    <property name="tools.dir" value="&quot;${directory::get-current-directory()}\Tools\&quot;"/>
    <exec program="Tools\ILMerge\ILMerge.exe" workingdir=".">
      <arg value="/t:Library"/>
      <arg value="/ndebug"/>      
      <arg value="/out:&quot;${build.dir}\Temp\ProjectName.Infrastructure.dll&quot;"/>
      <arg value="&quot;${build.dir}ProjectName.Core.dll&quot;"/>
      <arg value="&quot;${build.dir}Xceed.Compression.dll&quot;"/>
      <arg value="&quot;${build.dir}ProjectName.Infrastructure.dll&quot;"/>
      <arg value="&quot;${build.dir}ProjectName.Infrastructure.XmlSerializers.dll&quot;"/>
    </exec>
    <delete file="${build.dir}ProjectName.Core.dll"/>
    <delete file="${build.dir}Xceed.Compression.dll"/>
    <delete file="${build.dir}ProjectName.Infrastructure.dll"/>
    <delete file="${build.dir}ProjectName.Infrastructure.XmlSerializers.dll"/>
    <move file="${build.dir}\Temp\ProjectName.Infrastructure.dll" tofile="${build.dir}ProjectName.Infrastructure.dll"/>
    <delete dir="${temp.dir}" if="${directory::exists(temp.dir)}"/>
  </target>

说得更清楚一点。我可以使用核心库中的对象,但不能使用基础设施库中的对象。因为一旦它尝试实例化这些对象之一,.NET 似乎会尝试加载依赖项,但找不到它。

最佳答案

使用ILMerge 。它开箱即用即可执行此操作。

关于.net - 如何维护两个独立的项目,但将它们合并到一个 DLL 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1129411/

相关文章:

visual-studio - Visual Studio 2015丢失设置

c# - 在 .net 项目中使用 SilverLight 库 (dll)

c++ - 在c中编译dll时传递参数

c++ - 在 Visual Studio 中删除[某事]有什么作用?

c# - 是否有适用于 Mono 的 ILMerge 等效工具?

c# - 使用同一个库的两个不同版本

c# - 32 位快速统一哈希函数。使用 MD5/SHA1 并截掉 4 个字节?

c# - 如何使用只读属性通知 UI 更改?

c# - .NET:独立存储异常

.net-4.0 - ILMerge、.NET 4、NuGet : Unresolved assembly reference not allowed: CommandLine