NuGet 错误 NU1008

Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: PackageId.

问题

使用中央包管理时,必须在 PackageVersion 项中定义版本。

在项目文件中,你可能会看到:

<!-- In the project file. -->
<PackageReference Include="PackageId" Version="5.1.0" />

解决方案

  • 从 PackageId PackageReference 中删除版本。
  • 可能需在 Directory.Packages.props 中添加或更新 PackageId 的 PackageVersion 项

示例:

<!-- In the project file. -->
<PackageReference Include="PackageId" />
<!-- In the Directory.Packages.props -->
<PackageVersion Include="PackageId" Version="5.1.0" />

注意

请注意,IncludeAssets、PrivateAssets 等元数据应保留在 PackageReference 项中。