繁体   English   中英

Nuget package 创建 - Class 库以 Z303CB0EF9EDB9082D61BBBE5625D972AZ41 为目标框架不正确。

[英]Nuget package creation - Class library that targets .NET framework 4.6.1 can not target correct framework

我创建了一个 class 库,该库针对 .net 框架 4.6.1(几乎是一个空白的 canvas,使用单一方法返回字符串,仅用于测试目的)。 我想把它变成 nuget package。 我正在关注这篇文章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"

我尝试将依赖组添加到 .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>

我也试过:

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

我仍然得到同样的错误。

我尝试使用旧版本的 nuget,其中未显示警告消息,但同样的问题仍然存在(如果我尝试通过 package 管理器添加,它表示它没有依赖关系)。

警告:NU5128:在 nuspec 的依赖项组和 lib/ref 文件夹中声明的某些目标框架在其他位置没有完全匹配。 请参阅下面的操作列表。

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

如果我尝试通过 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. 目前, nuget pack命令不适用于具有 packageReference新 SDK 格式项目的 .net 框架项目

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

2.如果您的意思是no dependencies是当一个项目使用您的 package 时,它不会显示您的项目针对哪个框架,如下所示:

在此处输入图像描述 (我们可以看到您的 package 依赖于 Newtonsoft.Json 但我们找不到它针对的框架(net461)。)

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

在此处输入图像描述

希望以上所有内容有所帮助,如果我有任何误解,请随时纠正我:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM