简体   繁体   English

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

[英]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.

相关问题 .NET标准库能否以某种方式使用支持.NET Framework 4.6.1的nuget包 - Can .NET standard libraries somehow consume nuget packages, which support .NET Framework 4.6.1 无法将NUGET hdf5-v120-complete安装到具有框架4.6.1的.NET项目 - can't install NUGET hdf5-v120-complete to .NET project with framework 4.6.1 .NET Framework 4.6.1应用程序具有引用.NET Standard 1.4类库的错误 - .NET Framework 4.6.1 application has errors referencing .NET Standard 1.4 class library 强制nuget忽略目标框架冲突的软件包 - Force nuget to ignore package with conflicting target framework 具有 4.7.2 目标框架版本的 C# 项目可以在 .net 4.6.1 上运行吗 - Can C# projects that have 4.7.2 target framework version run on .net 4.6.1 如何使用Asp.Net.Identity和Entity Framework 6在Asp.Net Core 2.0 Target Framework 4.6.1中设置身份? - How can I setup identity in Asp.Net Core 2.0 Target Framework 4.6.1 using Asp.Net.Identity and Entity Framework 6? .net Core 2.0 - 使用 .NetFramework 4.6.1 而不是目标框架 .netCore 2.0 来恢复包。 软件包可能不完全兼容 - .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible 在目标框架中为什么需要.net 4.6.1是4.5.2 - Why .net 4.6.1 needed when in target framework is 4.5.2 asp.net核心目标框架4.6.1发布 - asp.net core target framework 4.6.1 publish 假货和 .net Framework 4.6.1 和系统 - Fakes and .net Framework 4.6.1 and System
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM