适用于多种框架的Nuget包

时间:2019-02-27 14:13:34

标签: msbuild nuget .net-standard

我正在尝试制作针对多个框架的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文件相同

2 个答案:

答案 0 :(得分:1)

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

您应该使用dotnet packmsbuild -t:pack

打包

答案 1 :(得分:0)

在csproj SDK样式文件中以nupsec xml属性为目标的多个框架。回到csproj,添加此TargetFrameworks(带有“ s”):

<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>

Edit the manifest,将这些行添加到定义TargetFrameworks的ProjectGroup中:

<files>
  <file src="bin\Release\net462\TestPackaging.dll" target="lib\net452\TestPackaging.dll" />
  <file src="bin\Release\netstandard2.0\TestPackaging.dll" target="lib\netstandard2.0\TestPackaging.dll" />
</files>

构建项目,然后将dll放入各自的目录中,并使用两个目标框架的源文件构建nuget。