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

六眼飞鱼酱① 提交于 2019-12-22 08:36:51

问题


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:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/44709212/the-content-folder-in-my-nuget-package-isnt-adding-the-files-to-the-root-when-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!