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

Nat*_*mer 5 .net ilmerge visual-studio

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

ProjectName.Core &
ProjectName.Infrastructure
Run Code Online (Sandbox Code Playgroud)

这是在典型的Onion体系结构中完成的,因此我可以松散耦合服务并获得更大的灵活性。基础结构项目引用核心项目。编译后,它们会生成这些DLL

ProjectName.Core.dll &
ProjectName.Infrastructure.dll
Run Code Online (Sandbox Code Playgroud)

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

ProjectName.Infrastructure.dll (or even ProjectName.dll)
Run Code Online (Sandbox Code Playgroud)

我尝试使用ILMerge来执行此操作,但是由于基础结构引用了Core,因此它会引发异常,因为它找不到Core dll。很明显,它本身并不内在。

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

ProjectName.Core &
ProjectName.DataAccess &
ProjectName.Web
Run Code Online (Sandbox Code Playgroud)

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

  <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>
Run Code Online (Sandbox Code Playgroud)

要更清楚一点。我可以使用核心库之外的对象,但不能使用基础结构库。因为一旦它试图实例化这些对象之一,.NET似乎试图加载该依赖关系但找不到它。

Ars*_*yan 1

据我所知,这在 Visual Studio 中是不可能的,但您可以将每个项目编译为网络模块,然后将它们作为 DLL 连接在一起。像这样编译:

csc misource1.cs misource2.cs misource3.cs /target:module
Run Code Online (Sandbox Code Playgroud)

然后与 al.exe 工具链接在一起,请参阅.netmodule 文件作为链接器输入C# 程序集