.NETStandard 库 nuget 包 - 无法安装在标准项目上
.NETStandard Library nuget package - cannot install on standard project
我有一个 .NET Core 项目 project.json
:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
我已经创建了 nuget 包(参见上文 postcompile
)并在 nuget 中发布。
然后我创建了标准 4.6.2 库,但无法安装程序包 - 错误是程序包不包含目标 .NET Framework 4.6.2 的有效程序集。
我应该如何准备 nuget 包以使其在标准库中可用?我认为目标 NETStandard 对核心项目和标准项目都有效。
您应该能够通过将 "net462" 添加到您的 project.json:
来添加对 .Net Framework 4.6.2 的支持
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"net462": {
"dependencies" : {
"System.Runtime": "4.0.20.0" // you may have to add this
// add here your dependencies
}
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
see also my project.json on github with a few supported frameworks
如果您检查 .Net Standard 的兼容性矩阵,它看起来像 .Net 4.6.2 只支持 NetStandard 1.5。在框架下,您的目标是标记为 vNext 的 1.6。
See here for the compatibility matrix to know what version you should target
换句话说,如果您将配置更改为以下内容,您应该能够自由引用该库:
"frameworks":
{
"netstandard1.5": {}
}
您不需要像另一个答案中建议的那样添加其他框架类型,因为 4.6.2 应该能够引用 1.5 标准。
我有一个 .NET Core 项目 project.json
:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
我已经创建了 nuget 包(参见上文 postcompile
)并在 nuget 中发布。
然后我创建了标准 4.6.2 库,但无法安装程序包 - 错误是程序包不包含目标 .NET Framework 4.6.2 的有效程序集。
我应该如何准备 nuget 包以使其在标准库中可用?我认为目标 NETStandard 对核心项目和标准项目都有效。
您应该能够通过将 "net462" 添加到您的 project.json:
来添加对 .Net Framework 4.6.2 的支持{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"net462": {
"dependencies" : {
"System.Runtime": "4.0.20.0" // you may have to add this
// add here your dependencies
}
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
see also my project.json on github with a few supported frameworks
如果您检查 .Net Standard 的兼容性矩阵,它看起来像 .Net 4.6.2 只支持 NetStandard 1.5。在框架下,您的目标是标记为 vNext 的 1.6。
See here for the compatibility matrix to know what version you should target
换句话说,如果您将配置更改为以下内容,您应该能够自由引用该库:
"frameworks":
{
"netstandard1.5": {}
}
您不需要像另一个答案中建议的那样添加其他框架类型,因为 4.6.2 应该能够引用 1.5 标准。