【发布时间】:2020-11-27 11:13:14
【问题描述】:
我已经定义并创建了一个仅内容包,用于在不同项目之间共享 JSON 模式。我使用nuget.exe打包它,并且可以成功地将它添加到.Net Framework 4.6库项目中。
但是当我尝试将其添加到 DotNet Core 3.1 库项目(NUnit 测试)时,出现以下错误:
NU1212 Invalid project-package combination for <package name>. DotnetToolReference project style can only contain references of the DotnetTool type
Nuget 支持文档(package type、content files)没有列出对仅内容包的任何限制(除了“假设它们是兼容的”)。问题是如何创建与 DotNet Core 3.1 库兼容的纯内容 Nuget 包?
我尝试按照this question 中的建议禁用除本地数据源以外的所有数据源,但这并没有什么不同。
这是.nuspec文件内容
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Package.JsonSchemas</id>
<version>0.0.1</version>
<packageTypes>
<packageType name="Dependency" />
</packageTypes>
<authors>me</authors>
<owners>me</owners>
<releaseNotes>Fill in later</releaseNotes>
<description>Set of JSON schemas.</description>
<tags>json, json-schema, tdv</tags>
<contentFiles>
<files include="JsonSchemas\*.json" buildAction="Content" copyToOutput="true" flatten="false" />
</contentFiles>
</metadata>
<files>
<file src="JsonSchemas\*.*" target="content\JsonSchemas" />
</files>
</package>
架构示例:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$defs": {
"ArrayItem": {
"type": "object"
}
},
"title": "dataset object",
"type": "object",
"properties": {
"Data": {
"type": "array",
"items": {
"$ref": "#/$defs/ArrayItem"
},
"default": []
}
},
"required": [ "Data" ]
}
【问题讨论】:
-
请在您的 nuspec 文件中使用它们:
<files><file src="JsonSchemas\*.*" target="content\JsonSchemas" /> <file src="JsonSchemas\*.*" target="contentFiles\any\any" /></files> -
嗨,关于这个问题的任何更新?如果那个人的回答能帮助你解决问题,请不要忘记标记它:)
-
嗨@PerryQian-MSFT,我按照你和 thatguy 的建议做了。我什至只是从 thatguy's 的答案中复制并粘贴了 nuspec 定义,但在 Visual Studio(现在是 16.7)中仍然收到相同的错误消息。
-
另外两个建议:先尝试使用最新的nuget.exe cli v5.6.0打包项目。其次,在你安装新版本的项目之前,你应该确保你的项目已经被移除了——做一个干净的步骤。然后,clean all nuget caches.
-
是的,谢谢,先清除所有 Nuget 缓存,然后重新安装软件包。
标签: c# visual-studio .net-core nuget nuget-spec