Nuget程序包创建-针对.NET Framework 4.6.1的类库无法针对正确的框架 [英] Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework

查看:599
本文介绍了Nuget程序包创建-针对.NET Framework 4.6.1的类库无法针对正确的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个针对.net Framework 4.6.1的类库(几乎是一块空白画布,只有一种方法可以返回字符串,仅用于测试目的).我想把它做成一个nuget包.我正在关注这篇文章 https://docs.microsoft.com/zh-cn/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-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). I want to make this into a 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:

"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"

我尝试将依赖项组添加到.nuspec文件:

I tried adding the dependency group to the .nuspec file:

<?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>

我也尝试过:

<?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.

我尝试使用nuget的旧版本,虽然未显示警告消息,但仍然存在相同的问题(如果我尝试通过程序包管理器进行添加,则表示它没有依赖性).

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).

推荐答案

警告:NU5128:在依赖项中声明了一些目标框架 nuspec组和lib/ref文件夹不完全匹配 在另一个位置.请参阅下面的操作列表.

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.

这是Github/Nuget中的一个未解决问题,请参阅#8713 .我可以在VS2017中使用Nuget V5.3重现相同的问题,并且如果我使用Nuget V5.2或更早版本,则此问题将消失.对于这种情况,恐怕您必须使用Nuget.exe的早期版本,直到团队发布该修补程序为止.

This is an open issue in Github/Nuget, see #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. For this situation, I'm afraid you have to use earlier versions of Nuget.exe until the team releases the fix.

如果我尝试通过包管理器添加,它说它没有 依赖项

If I try to add via the package manager, it says it has no dependencies

1.尽管您的软件包项目依赖于某些nuget软件包,但如果显示no package dependencies,请检查您是否正在使用packageReference来管理当前项目中的nuget.目前,nuget pack命令不适用于带有packageReference的.net框架项目新的SDK格式项目.

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.

您可以从 Leo的答案中查看详细信息,以解决此问题.

You can check details from Leo's answer to resolve this issue.

2.如果no dependencies的意思是当一个项目使用了程序包时,它不会像这样显示您的项目目标的框架:

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:

(我们可以看到您的软件包取决于Newtonsoft.Json,但找不到它针对的框架(net461).)

(We can see your package depends on Newtonsoft.Json but we can't find which framework it targets(net461).)

为此,我们需要在包装时使用nuget pack xx.nuspec之类的命令将dependencies+group添加到包装中.然后,我们可以看到目标框架和依赖包,如下所示:

For this, we need to use command like nuget pack xx.nuspec to add the dependencies+group into package when packing. 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 :)

这篇关于Nuget程序包创建-针对.NET Framework 4.6.1的类库无法针对正确的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆