出身背景
我希望将dll从我的数据访问层复制到我的应用层,以便AutoFac加载dll,但是我不希望有项目引用,这样开发人员就不会意外引用&直接使用数据访问层类。
问题
我的应用层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远离应用层的目标。