IoC:具有ReferenceOutputAssembly = false的ProjectReference,但仍需要nuget包

时间:2019-01-16 17:46:43

标签: dependency-injection .net-core msbuild nuget autofac

背景

我正在出于自动加载的目的,将dll从我的数据访问层复制到我的应用程序层,以加载dll,但是不希望有项目引用,因此开发人员不能意外地引用并使用数据访问层类。

问题

我的Application Tier csproj文件中有类似的内容。

这一直很好,但是我现在意识到它并没有复制瞬态依赖项,即nuget包

<ProjectReference Include="..\MyProj.csproj">
  <!-- We don't wish a developer to accidentally reference the DAL tier directly in the UI, only as a dependency. -->
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
  <!-- As the composite root (in DI terms) we still want to ensure that the UI tier has a copy of the DAL dll to load up.-->
  <OutputItemType>Content</OutputItemType>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <!-- DebugSymbolsProjectOutputGroup copies PDB files, but not for Visual Studio, which is still fine as Visual Studio knows how to get debugging information.  -->
  <Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
</ProjectReference>

伴随:

  <PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

通读大量的github门票和博客,例如:

https://www.erikheemskerk.nl/transitive-nuget-dependencies-net-core-got-your-back/

https://github.com/NuGet/Home/issues/6151

https://github.com/dotnet/sdk/issues/747

玩我能想到的所有组合,似乎并没有复制nuget包。

唯一可行的方法是:

<ReferenceOutputAssembly>true</ReferenceOutputAssembly>

这是使数据访问层dll远离应用程序层的目标的失败。

1 个答案:

答案 0 :(得分:1)

只需创建您自己的自定义复制目标即可复制您想要的内容。没有错。然后,您应该可以删除上面显示的ProjectReference。