我希望这里缺少一些简单的东西。我正在尝试维护两个独立的项目
ProjectName.Core &
ProjectName.Infrastructure
这是在典型的 Onion 架构中创建的,因此我可以松散地耦合我的服务并获得更大的灵活性。基础设施项目引用核心项目。编译后,它们会生成这些 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=""${directory::get-current-directory()}\Tools\""/>
<exec program="Tools\ILMerge\ILMerge.exe" workingdir=".">
<arg value="/t:Library"/>
<arg value="/ndebug"/>
<arg value="/out:"${build.dir}\Temp\ProjectName.Infrastructure.dll""/>
<arg value=""${build.dir}ProjectName.Core.dll""/>
<arg value=""${build.dir}Xceed.Compression.dll""/>
<arg value=""${build.dir}ProjectName.Infrastructure.dll""/>
<arg value=""${build.dir}ProjectName.Infrastructure.XmlSerializers.dll""/>
</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 似乎会尝试加载依赖项但找不到它。