NuGet 依赖项 - 在指定 targetFramework 后收到 NU5128 警告

7
我有一个针对.NET Framework 4的项目。我正在使用nuget.exe(版本5.6.0.6591)创建NuGet包。该项目本身没有其他引用,只有Microsoft.CSharp和System程序集(这些程序集都没有设置特定版本)。
首先,我创建了一个MyProject.nuspec文件(通过在MyProject.csproj文件夹中运行nuget spec)。然后我尝试运行nuget pack MyProject.csproj并获得了NuGet包(.nupkg存档)。但是我也收到了这个警告:
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.0 to the nuspec

根据https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128,我已经修改了我的.nuspec文件,现在它看起来像这样(注意<dependencies>标签):
<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes></releaseNotes>
    <copyright>Copyright 2020</copyright>
    <tags>my tags here</tags>
    <dependencies>
      <group targetFramework=".NETFramework4.0" />
    </dependencies>
  </metadata>
</package>

然而,我仍然收到警告。当我在生成的.nupkg档案中打开.nuspec文件时,那里只有空的<dependencies />标签。
我找到的一个解决方法是,在.nuspec文件中替换变量并调用nuget pack MyProject.nuspec,而不是nuget pack MyProject.csproj。然后我会得到相同的.nuspec文件,包括目标框架依赖项,在我的结果.nupkg档案中。但这使我失去了让nuget自动为我填写版本的功能。
无论哪种方式,当我使用-Verbosity detailed运行nuget pack时,我看到Dependendecies为空:
Id: MyId
Version: 1.0.0
Authors: Me
Description: My description
Tags: my, tags, here
Dependencies:

似乎当我在.csproj上调用nuget pack时,它会填充变量,但它也会删除依赖项,因为它认为它们是空的,然后它会给我警告。如果我在.nuspec上调用nuget pack,它会按原样打包,包括依赖项,从而避免警告。
有什么想法可以解决警告,同时让nuget填充变量?如果我的软件包中没有指定目标框架,对于使用该软件包的任何人是否会产生负面影响?

大卫,你解决了你的问题吗?我也遇到了同样的问题。 - DhyMik
@DhyMik 没有,我还没有找到确切的解决方案。但是,我注意到在我的TFS构建计划中创建包时没有警告。它使用较旧版本的NuGet.exe(4.1.0.2450)。所创建的包的依赖项为空,一切似乎都正常工作。 - David Hrbek
2个回答

0

版本5.2.0同样有效。我无法解决比这个版本更新的问题(直到版本5.8.1)。


0

我曾经遇到过同样的问题。关于警告 NU5128(场景1)的文档建议在项目上运行nuget的pack目标而不是调用nuget pack。请注意,这需要您的项目使用PackageReference来管理自己的nuget依赖项。

安装了NuGet.Build.Tasks.Pack包并使用msbuild -t:pack -p:Authors=JustAGuy构建后,我得到了预期的nuspec依赖项自动生成。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接