Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The content folder in my nuget package isn't adding the files to the root when installing the package

I am running .net core 1.1 and nuget 3.5.

Here is my nuspec:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>ClassLibrary1</id>
    <version>1.0.0.4</version>
    <title>Class Library Test Content</title>
    <authors>name</authors>
    <owners>name</owners>        
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>package to test config file transfer</description>
    <copyright>Copyright 2017</copyright>
    <tags>TagUno TagDos</tags>
    <contentFiles>
      <files include="appsettings.json" buildAction="Content" copyToOutput="true" />
    </contentFiles>
  </metadata>

  <files>
    <file src="bin\Debug\net462\classlibrary1.dll" target="lib\net462\classlibrary1.dll" />
    <file src="appsettings.json" target="content\net462\appsettings.json" />
  </files>

</package>

It produces this package: enter image description here

As we can see, the appsettings.json file is located in the content folder in the nuget package.

However, when I install the package to my project, the appsettings.json file is not copied to the project root.

What am I missing? Or is this done differently in .net core?

like image 801
ChasetopherB Avatar asked Jun 22 '17 20:06

ChasetopherB


1 Answers

The content subdirectory is only used for packages.config projects.

Projects using the PackageReference style of NuGet references use the contentFiles section instead which allows to specify the build action to use. Those files aren't copied to the project, but are included as items in the project and optionally set to copy to the consuming project's build output:

<package>
  <metadata>
    ...
    <contentFiles>
        <files include="appsettings.json" buildAction="Content" copyToOutput="true" />
    </contentFiles>
  </metadata>
  <files>...</files>
</package>

See the contentFiles documentation for more detail.

Note that those files aren't copied to the project but included logically. Only packages.config projects support this since there was no other way to contribute files - the documentation also states that these files should have been considered immutable anyway.

like image 152
Martin Ullrich Avatar answered Oct 14 '22 07:10

Martin Ullrich