[英]Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework
I created a class library that targets .net framework 4.6.1 (so pretty much a blank canvas, with a single method to return a string, just for testing purposes).我创建了一个 class 库,该库针对 .net 框架 4.6.1(几乎是一个空白的 canvas,使用单一方法返回字符串,仅用于测试目的)。 I want to make this into a nuget package.
我想把它变成 nuget package。 I'm following this article https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework , but when I get to "nuget pack" I get the following warning:
我正在关注这篇文章https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework ,但是当我到达“ nuget pack”我收到以下警告:
"WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
- Add a dependency group for .NETFramework4.6.1 to the nuspec"
I tried adding the dependency group to the.nuspec file:我尝试将依赖组添加到 .nuspec 文件中:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>H</description>
<copyright>Copyright 2019</copyright>
<tags>blah</tags>
<dependencies>
<group targetFramework=".NETFramework4.6.1" />
</dependencies>
</metadata>
</package>
and I also tried:我也试过:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Author</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>H</description>
<copyright>Copyright 2019</copyright>
<tags>blah</tags>
<dependencies>
<group targetFramework="net461" />
</dependencies>
</metadata>
</package>
I still get same error.我仍然得到同样的错误。
I tried using older versions of nuget, where the warning message isn't shown, but the same problem persists (If I try to add via the package manager, it says it has no dependencies).我尝试使用旧版本的 nuget,其中未显示警告消息,但同样的问题仍然存在(如果我尝试通过 package 管理器添加,它表示它没有依赖关系)。
WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location.
警告:NU5128:在 nuspec 的依赖项组和 lib/ref 文件夹中声明的某些目标框架在其他位置没有完全匹配。 Consult the list of actions below.
请参阅下面的操作列表。
This is an open issue in Github/Nuget
, see #8713 .这是
Github/Nuget
中的一个未解决问题,请参阅#8713 。 I can reproduce same issue in my VS2017 with Nuget V5.3, and this issue goes away if I use Nuget V5.2 or earlier.我可以使用 Nuget V5.3 在我的 VS2017 中重现同样的问题,如果我使用 Nuget V5.2 或更早版本,这个问题就会消失。 For this situation, I'm afraid you have to use earlier versions of
Nuget.exe
until the team releases the fix.对于这种情况,恐怕您必须使用早期版本的
Nuget.exe
,直到团队发布修复程序。
If I try to add via the package manager, it says it has no dependencies
如果我尝试通过 package 管理器添加,它说它没有依赖项
1.If it displays no package dependencies
though your package project depends on some nuget packages, please check if you're using packageReference
to manage nuget in your current project. 1.If it displays
no package dependencies
though your package project depends on some nuget packages, please check if you're using packageReference
to manage nuget in your current project. For now, nuget pack
command doesn't work well for .net framework projects with packageReference or new SDK format projects .目前,
nuget pack
命令不适用于具有 packageReference或新 SDK 格式项目的 .net 框架项目。
You can check details from Leo's answer to resolve this issue.您可以从Leo 的答案中查看详细信息以解决此问题。
2.If the no dependencies
you mean is that when one project consumes your package, it doesn't display which framework your project targets like this: 2.如果您的意思是
no dependencies
是当一个项目使用您的 package 时,它不会显示您的项目针对哪个框架,如下所示:
(We can see your package depends on Newtonsoft.Json but we can't find which framework it targets(net461).)
(我们可以看到您的 package 依赖于 Newtonsoft.Json 但我们找不到它针对的框架(net461)。)
For this, we need to use command like nuget pack xx.nuspec
to add the dependencies+group
into package when packing.为此,我们需要在打包时使用
nuget pack xx.nuspec
之类的命令将dependencies+group
添加到 package 中。 Then we can see both targets framework and dependent packages like this:然后我们可以看到目标框架和依赖包,如下所示:
Hope all above helps and if I misunderstand anything, feel free to correct me:)希望以上所有内容有所帮助,如果我有任何误解,请随时纠正我:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.