Home: PrivateAssets and ExcludeAssets should be independent

Created on 16 May 2018  路  2Comments  路  Source: NuGet/Home

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): I've tried dotnet.exe and nuget.exe and msbuild.exe as it ships with my VS.

NuGet version (x.x.x.xxx): 4.6.1

dotnet.exe --version (if appropriate): 2.1.200

VS version (if appropriate): 27713.00.d15.8

OS version (i.e. win10 v1607 (14393.321)): Windows 10 RS4

Worked before? If so, with which NuGet version: No

Detailed repro steps so we can see the same problem

In a .NET SDK style project, reference a package while specifying PrivateAssets and ExcludeAssets attributes, like this:

<PackageReference Include="CodeGeneration.Roslyn.BuildTime" PrivateAssets="none" ExcludeAssets="Build" />

Expected result

I expect that my project will not consume the build elements of the package, but that my own package's respective consumers will consume the build elements of the referenced package.

In other words, I don't want my project importing the build folder .targets file from that package, but I do want this expressed in my package's .nuspec file:

<dependency id="CodeGeneration.Roslyn.BuildTime" version="0.4.42" include="all" />

Actual result

<dependency id="CodeGeneration.Roslyn.BuildTime" version="0.4.42" include="Runtime,Compile,Native,ContentFiles,Analyzers" />

Additional discussion

The fact that I can specify PrivateAssets (which is documented to influence how the dependency is expressed to others), _and_ I can specify ExcludeAssets/IncludeAssets (which influences how I get my own dependency), is fantastic, except that when I use the two together, they interact such that I might as well not set PrivateAssets because it seems to be ignored.

In another related case to this, I actually wanted these two attributes on my PackageReference: PrivateAssets="none" IncludeAssets="none" because I wanted to express a dependency downstream that I myself didn't share. But that simply suppresses the dependency in the .nuspec file. 馃槮

Sample Project

refissue.zip

Pack Icebox 2 PackageReference DCR

Most helpful comment

This has come up for a few of my packages.

In some cases, the scenario is that I'm creating a specialized package that helps create a development environment for the consuming project (it usually includes build authoring). Part of that environment requires that the consumer also reference other packages that the build authoring offered by my package requires. But building my own package itself does not require those packages.

In another (perhaps more common) case, it's a library with analyzers. I have a library package, and an analyzers package. Whenever someone consumes my library I want them to get the analyzers for it too, so my library package depends on the analyzers package. But my library itself does not need or want the analyzers applied to itself.

If NuGet didn't want to support this, I don't understand why there are distinct attributes to track downstream dependencies vs. my own dependencies. Being distinct is super useful -- or would be if they worked. At the moment I don't even know how to reason about these attributes when used together.

All 2 comments

I have my reservations about this requirement and It seems very specific to work around something else. Why would someone allow flowing some assets from it's own dependency without even consuming itself?

Since NuGet has these explicit properties PrivateAssets or ExcludeAssets/IncludeAssets, we're even thinking about this scenario but most other package managers will have a uber scope attribute to define the scope of a package which is implicitly applied to rest of it's dependencies as well, which seems like a right thing to do.

This has come up for a few of my packages.

In some cases, the scenario is that I'm creating a specialized package that helps create a development environment for the consuming project (it usually includes build authoring). Part of that environment requires that the consumer also reference other packages that the build authoring offered by my package requires. But building my own package itself does not require those packages.

In another (perhaps more common) case, it's a library with analyzers. I have a library package, and an analyzers package. Whenever someone consumes my library I want them to get the analyzers for it too, so my library package depends on the analyzers package. But my library itself does not need or want the analyzers applied to itself.

If NuGet didn't want to support this, I don't understand why there are distinct attributes to track downstream dependencies vs. my own dependencies. Being distinct is super useful -- or would be if they worked. At the moment I don't even know how to reason about these attributes when used together.

Was this page helpful?
0 / 5 - 0 ratings