Reputation: 36573
I have a project MySdk.csproj that I'm packing at build time via dotnet pack. I want to express that this project has a transitive dependency on Trans.nupkg, but I don't actually want to import all the assets from Trans.nupkg during the build of MySdk.csproj. I DO want a consumer (call it Consumer.csproj) of MySdk.nupkg to get all the assets from Trans.nupkg.
If I ExcludeAssets for Trans.nupkg from MySdk.nupkg then the nuspec and nupkg for MySdk.nupkg reflects the exclusion and when Consumer.csproj references MySdk.nupkg it won't get the transitive assets.
Is there a way to accomplish this?
Thanks.
UPDATE:
If I try to set PrivateAssets to None and ExcludeAssets to build for Trans.nupkg reference from MySdk.csproj like this:
<PackageReference Include="Trans" Version="1.0.*" PrivateAssets="None" ExcludeAssets="build" />
the generated nuspec in MySdk.nupkg looks like this:
<dependency id="Trans" version="1.0.0" include="Runtime,Compile,Native,ContentFiles,Analyzers" />
which means that when Consumer.csproj adds a reference like this:
<PackageReference Include="MySdk" Version="1.0.0" />
the transitive reference back to Trans.nupkg won't include the custom build targets, which is the opposite of what I'm trying to accomplish.
Upvotes: 2
Views: 2095
Reputation: 100581
While ExcludeAssets
controls which assets the MySdk.csproj will consume, PrivateAssets
specifies which assets will not flow across a transitive dependency.
The default for PrivateAssets
is contentfiles;analyzers;build
which is the reason that the Consumer.csproj will not get built-time assets (.pros/.targets files), roslyn analysers and content files by default.
To change, this reference the Trans
package setting PrivateAssets
to none
which will make Consumer.csproj behave as if it directly referenced the Trans
package (example also excluding build-time dependencies from the MySdk project):
<PackageReference Include="trans" PrivateAssets="none" ExcludeAssets="contentfiles;build" />
For more information see Controlling dependency assets.
Upvotes: 3