Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentFiles to output directory in project which refers a nuget which refers another nuget package #9297

Bramvanelderen10 opened this issue Mar 13, 2020 · 6 comments


Copy link

@Bramvanelderen10 Bramvanelderen10 commented Mar 13, 2020

I'm building multiple nuget packages which include content files and can refer each other. These content files should always be copied to output directory.

The problem i'm having is that content files from a nuget package are correctly outputted to the output directory if the project references the nuget directly. But if a nuget package refers another nuget package with contentfiles, these content files will not copy to the output directory and are located in the wrong path.

Does anyone know a solution to this problem?

I've added an example to the repo here:

For context:

So lets say i have the following 2 packages

  • Base package
    • resource/contentFileBase.json
  • Utilities package
    • resource/contentFileUtilities.json
    • references the base package

In both projects csproj files i have defined the following entries for the content files

In base:

<Content Include="resource/contentFileBase.json">

In utilities:

<Content Include="resource/contentFileUtilities.json">

Now i package both the base package and the utilities package using dotnet pack. The resulting nuspec for the Utilities package will be generated:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="">
      <group targetFramework=".NETCoreApp2.2">
        <dependency id="base" version="0.0.1" exclude="Build,Analyzers" />
      <files include="any/netcoreapp2.2/resources/contentFileUtilities.json" buildAction="Content" copyToOutput="true" />
      <files include="any/netcoreapp2.2/contentFileBase.json" buildAction="Content" />

As you can immidiatly see in the nuspec the element for contentFileBase.json is invalid. It is missing both the resources/ path and the copyToOuput="true" attribute

Here a screenshot of the setup and the problem:
enter image description here

Used dotnet cli dotnet pack command. With dotnet core 2.2.4


This comment has been minimized.

Copy link

@donnie-msft donnie-msft commented Mar 16, 2020

By default, all assets are Private assets. You would need to remove contentfiles from the PrivateAssets section of your PackageReference.

Add this to your Package Reference

<PackageReference .....>

The documentation for this is

By the way...did you already see this doc and does it make sense? If it's not clear, I'll make sure we have an issue to improve this section of Docs. Thanks for any feedback!


This comment has been minimized.

Copy link

@Bramvanelderen10 Bramvanelderen10 commented Mar 17, 2020

@donnie-msft That worked! I read the documentation, where i went wrong was the IncludeAssets element, i thought if i add that with the all value that it would include all files from the package.

I do still have a small problem. Now i do see the file in the resources folder where i expect, but there is a copy still in the root directory. Can this be removed somehow? I've updated the demo project:

Thank you very much


This comment has been minimized.

Copy link

@donnie-msft donnie-msft commented Mar 26, 2020

@Bramvanelderen10 Glad you're making progress, let us know if you have other concerns.

For the small problem, try removing this from base.csproj:

    <None Remove="resources\base.json" />

This comment has been minimized.

Copy link

@Bramvanelderen10 Bramvanelderen10 commented Mar 26, 2020

One last question, I tried removing that element but it did not work. I've also tried playing around with different configurations in PrivateAssets, IncludeAssets and ExcludeAssets but all of that did not work.

The only thing that seems to work now is after i use dotnet pack and go to the generated package and edit the nuspec in there. Where i set the buildAction to none manually like:


But if i set the buildAction to none in visual studio it will change the csproj element to a None element which is not included as contentFile.


This comment has been minimized.

Copy link

@rrelyea rrelyea commented Mar 26, 2020

what if you set Pack="true" on the None item in csproj? that should pack it...and stay buildaction none, right?


This comment has been minimized.

Copy link

@Bramvanelderen10 Bramvanelderen10 commented Mar 27, 2020

Thats worked thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.