IoC: ProjectReference with ReferenceOutputAssembly = false, but still want nuget packages

Viewed 357

Background

I'm looking to copy dll's from my data access tier into my application tier for the purposes of AutoFac to load up the dlls, however don't wish there to be a project reference so a developer cannot accidentally reference & use a data access tier class directly.

The problem

I have something like this in my Application Tier csproj file.

This has been working great, but I have now realised that it's not copying the transient dependencies i.e. the nuget packages

<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>

Along with:

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

Reading through swarms of github tickets and blogs, a few for example:

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

And playing with everything combination I can think of, doesn't seem to copy the nuget packages.

The only way which works is:

<ReferenceOutputAssembly>true</ReferenceOutputAssembly>

Which sort of defeats the objective of keeping the data access tier dll away from the application tier.

1 Answers

Just make your own custom copy target to copy over what you want. Nothing wrong with that. And then you should be able to remove the ProjectReference shown above.

Related