问题描述
我正在运行 .net core 1.1 和 nuget 3.5.
I am running .net core 1.1 and nuget 3.5.
这是我的 nuspec:
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="binDebug
et462classlibrary1.dll" target="lib
et462classlibrary1.dll" />
<file src="appsettings.json" target="content
et462appsettings.json" />
</files>
</package>
它产生这个包:
如我们所见,appsettings.json 文件位于 nuget 包的 content 文件夹中.
As we can see, the appsettings.json file is located in the content folder in the nuget package.
但是,当我将包安装到我的项目时,appsettings.json 文件不会复制到项目根目录.
However, when I install the package to my project, the appsettings.json file is not copied to the project root.
我错过了什么?或者这在 .net core 中的做法不同吗?
What am I missing? Or is this done differently in .net core?
推荐答案
content
子目录仅用于 packages.config
项目.
The content
subdirectory is only used for packages.config
projects.
使用 PackageReference
样式的 NuGet 引用的项目使用 contentFiles
部分代替它允许指定要使用的构建操作.这些文件不会复制到项目中,而是作为项目包含在项目中,并可选择设置为复制到使用项目的构建输出:
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.
请注意,这些文件不会复制到项目中,而是按逻辑包含在内.只有 packages.config
项目支持这一点,因为没有其他方法可以贡献文件 - 文档还指出这些文件无论如何都应该被认为是不可变的.
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.
这篇关于安装包时,我的 nuget 包中的内容文件夹未将文件添加到根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!