【发布时间】:2020-03-05 00:34:59
【问题描述】:
我创建了一个面向 .net 框架 4.6.1 的类库(几乎是一个空白画布,只有一个方法可以返回一个字符串,仅用于测试目的)。我想把它做成一个nuget包。我正在关注这篇文章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,但未显示警告消息,但同样的问题仍然存在(如果我尝试通过包管理器添加,它说它没有依赖项)。
【问题讨论】:
-
将生成的包以 ZIP 格式打开,然后检查其中的文件夹结构。请编辑您的问题以包括在内。
-
你的项目会有nuget依赖吗,如果有,是否有必要使用packages.config?如果答案是否定的或“我不知道”,请改用following the instructions to create a
.NET Standardpackage。如果您需要以 netfx 为目标,则在解决方案资源管理器中右键单击项目,选择编辑项目文件并将TargetFramework元素更改为使用net461而不是netstandard2.0。打包(使用 VS 或 dotnet.exe),看看你是否有同样的问题 -
嗨,这个问题有什么更新吗?除了 nuget pack,您还可以考虑使用
msbuild /t:pack命令。我假设您在带有 packagereference 的 .net 框架项目中,然后您可以检查msbuild command是否可以满足您的需求。可能会有所帮助:-)
标签: c# visual-studio nuget