Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable transitive PackageReference dependency for a specific MsBuild project

I am migrating an old style MsBuild csproj project to using PackageReference format and have run into a problem with transitive dependencies.

Consider the following Project A reference NuGet package B and C, each containing one single assembly using PackageReference. On Build Project A uses IL merge to incorporate B as public symbols in the A assembly and C as internalized symbols. Project D have a project reference to A.

The transitive dependencies case D to reference A, B and C. When building D, compile errors of the type error CS0433: The type 'X' exists in both 'A' and 'B' occur.

Is there any way to force D to not add an explicit reference to B or C in the scenario above?

like image 463
Viktor Griph Avatar asked Sep 06 '18 15:09

Viktor Griph


People also ask

What is ExcludeAssets?

ExcludeAssets. These assets will not be consumed. none. PrivateAssets. These assets will be consumed but won't flow to the parent project.

What is transitive dependency NuGet?

GitHub - muiriswoulfe/NuGet-Transitive-Dependency-Finder: The NuGet Transitive Dependency Finder analyzes .NET projects and solutions to find superfluous dependencies that have been explicitly added to projects. The goal is to simplify dependency management.

What is PrivateAssets?

Private assets are investments that are typically not publicly listed and traded.


1 Answers

Disable transitive PackageReference dependency for a specific MsBuild project

If I understand you correct, you can try to use property <PrivateAssets>all</PrivateAssets>or PrivateAssets="all" for the PackageReference. If you have a package that's marked with private assets it merely prevents it from flowing to parent project or getting packed.

enter image description here

<PackageReference Include="B" Version="1.0.0" PrivateAssets="all">
<PackageReference Include="C" Version="1.0.0" PrivateAssets="all">

You can check the document Controlling dependency assets and this thread for some details.

Hope this helps.

like image 200
Leo Liu-MSFT Avatar answered Sep 22 '22 00:09

Leo Liu-MSFT