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

Dav*_*bek 7 .net nuget nuget-spec

我有一个针对 .NET Framework 4 的项目。我正在使用nuget.exe(version 5.6.0.6591) 创建 NuGet 包。Microsoft.CSharp项目本身除了程序集之外没有其他引用System(这些都没有特定的版本集)。

首先,我创建了一个MyProject.nuspec文件(通过nuget specMyProject.csproj文件夹中运行)。然后我尝试运行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
Run Code Online (Sandbox Code Playgroud)

根据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>
Run Code Online (Sandbox Code Playgroud)

但是,我仍然收到警告。当我打开.nuspec生成的.nupkg存档中的文件时,那里只有空<dependencies />标签。

我发现的一种解决方法是替换 file 中的变量.nuspec并调用nuget pack MyProject.nuspec而不是nuget pack MyProject.csproj. 然后我在生成的存档中获得相同的.nuspec文件,包括目标框架依赖项.nupkg。但这剥夺了我nuget自动为我填写版本的权利。

不管怎样,当我运行时nuget pack-Verbosity detailed我看到它们Dependendecies是空的:

Id: MyId
Version: 1.0.0
Authors: Me
Description: My description
Tags: my, tags, here
Dependencies:
Run Code Online (Sandbox Code Playgroud)

似乎当我调用时nuget pack.csproj它填充了变量,但它也删除了依赖项,因为它认为它们是空的,但之后它给了我警告。如果我调用nuget packon .nuspec,它会按原样打包,包括依赖项,从而避免警告。

nuget有什么想法如何在填写变量时解决警告吗?我的包中未指定目标框架这一事实会对使用该包的任何人产生负面影响吗?

小智 0

5.2.0 版本也能正常工作。我无法使用比该版本更高的版本(最高版本 5.8.1)解决该问题。