Search code examples
.net.net-coremsbuildnuget

If a nuget specifies PrivateAssets=all why specify IncludeAssets?


The nuget installation pages for development-only packages (e.g. analysers, build tools), typically show this:

<PackageReference Include="Foo" Version="1.2.3">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime;build;native;contentfiles;analyzers;...</IncludeAssets>
</PackageReference>

For such packages, the PrivateAssets property is always set to all.

The IncludeAssets property is always specified too. Surely it's redundant?


Solution

  • The compile asset is not listed in IncludeAssets, so in fact it's not the same. The lack of compile assets means that if the package contains any dlls under lib/ or ref/, you won't be able to call those APIs, which is a good thing since the package won't be listed as a dependency on your own package.

    If you remove that IncludeAssets line and call APIs, then anyone using your package (and calls an API which uses your "privateassets=all" package reference), then at runtime a FileNotFoundException will be thrown.

    So, having an IncludeAssets line that removes compile is a good thing, although the same could be achieved by replacing it with <ExcludeAssets>compile</ExcludeAssets>, which would have been much clearer.

    My gut feeling is that runtime should also be excluded, but I have no idea why the people working on NuGet at the time this was implemented made the different decision.