Nuget Content Files in .Net core solution not getting copied when installing through Nuget

There is a nuget blog post about this, and it just isn't supported at this time.

Supported Project Types

This feature is only for packages that will be installed to projects that are managed using a project.json file. Currently only two projects types are managed by a project.json.

The contentFiles option is not available for other project types.

It's really a pity this basic functionality has been excluded from the .net Core projects. Especially because PCL is supported, which is a subset of a .net Core project.

There are quite some issues on GitHub about this, and it's very unclear whether or not this feature is coming back any time soon.


It seems it is still not supported. Only way to "hack" it is with MSBuild Targets and Build events.

According to this documentation:

build
MSBuild .targets and .props files Automatically inserted into the project file or project.lock.json (NuGet 3.x+).

So to make it work with any file, e.g.: "config.xml" as Nuget Static Content:

  1. Create your XY.nuspec file (as you would normally)
  2. Include config.xml into the Nuget: <file src="config.xml" target="contentFiles\any\any\config.xml" />
  3. Add a new .targets file XY.targets
  4. Include new XY.targets file into your package to the "build" folder. <file src="XY.targets" target="build"/>

Content of the XY.targets file

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ContentFilesPath>$(MSBuildThisFileDirectory)..\contentFiles\any\any\</ContentFilesPath>
  </PropertyGroup>
  <Target Name="CopyConfigs" BeforeTargets="PreBuildEvent">
    <Copy SourceFiles="$(ContentFilesPath)\config.xml" DestinationFiles="$(ProjectDir)config.xml" SkipUnchangedFiles="true" Condition="!Exists('$(ProjectDir)config.xml')"></Copy>
  </Target>
</Project>

After packaging and installing the Nuget this MSBuild Target will be part of the Cached package and will run on each build (currently before build).

Issues with this solution:

  • Added files still linked until you build your solution. During the build paheses (BeforeTargets="") files are copied. Until this files still are just linked!!!
  • If you set up your content files to have Build actions and be copied to the Output directory of the project those settings will be lost!

Unfortunately this is the best solution for now.