Matt Mason
Matt Mason

Reputation: 2724

dotnet publish, contentFiles, and transitive nuget dependencies

Is it possible for dotnet publish to copy contentFiles to output from a transitive package dependencies?

In this scenario, I have three projects:

  1. Content, which has a nuspec containing:
<contentFiles>
  <files include="any/any/someContent.txt" buildAction="None" copyToOutput="true" flatten="false"/>
</contentFiles>
  1. Lib, which has a PackageReference to Content nuget
  2. ConsoleApp, which has a PackageReference to Lib nuget

The Lib project shows the contentFiles in the project explorer and copies to output on build, but the ConsoleApp project does neither.

I need dotnet publish ConsoleApp.csproj to include someContent.txt from the Content nuget in the publish output.

Somewhat related posts for context:

Upvotes: 5

Views: 1518

Answers (1)

Jos&#233; Pedro
Jos&#233; Pedro

Reputation: 1095

contentFiles are Private Assets by default. You need to change the PrivateAssets metadata in the reference from Lib to Content, so that it doesn't include contentFiles, like this:

<ProjectReference Include="...">
    <PrivateAssets>analyzers;build</PrivateAssets>
</ProjectReference>

More information here: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets

Upvotes: 7

Related Questions