首页 > 解决方案 > 用于多个框架的 Nuget 包

问题描述

我正在尝试制作针对多个框架的 nuget 包。但它不起作用。csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
   <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
   <OutputType>Library</OutputType>
   <TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
   <NuGetPackageImportStamp />
 </PropertyGroup>

运行命令:

C:\Repos\Random\TestStuff\.nuget\nuget pack "C:\Repos\Random\TestStuff\TestPackaging\TestPackaging.csproj"

它给了我错误:

错误 NU5012:找不到“bin\Debug\TestPackaging\bin\Debug\”。确保项目已经构建。

如果我将配置更改为:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
  <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
   <OutputType>Library</OutputType>
   <TargetFramework>netstandard2.0</TargetFramework>
   <NuGetPackageImportStamp />
 </PropertyGroup>
</Project>

一切正常。我错过了什么?改变我运行它的位置没有区别。

编辑:运行命令

C:\Repos\Random\TestStuff\.nuget\nuget pack "C:\Repos\Random\TestStuff\TestPackaging\TestPackaging.csproj" -build

给出不同的错误:

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:00.50
Packing files from 
'C:\Repos\Random\TestStuff\TestPackaging\bin\Debug\TestPackaging\bin\Debug'.
Could not find a part of the path 
'C:\Repos\Random\TestStuff\TestPackaging\bin\Debug\TestPackaging\bin\Debug'.

与 nuspec 文件相同

标签: msbuildnuget.net-standard

解决方案


nuget.exe 不支持打包 PackageReference 项目,SDK 项目始终是 PackageReference。

您应该使用dotnet packmsbuild -t:pack


推荐阅读