Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget pack for multiple frameworks

I am trying to make nuget package targeting multiple frameworks. But it doesn't work. csproj file:

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

running command:

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

It gives me error:

Error NU5012: Unable to find 'bin\Debug\TestPackaging\bin\Debug\'. Make sure the project has been built.

If I change config to:

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

everythings works fine. What am I missing? Changing location where I am running it from makes no difference.

EDIT: running command

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

gives different error:

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'.

same with nuspec file

like image 354
Shawnas Avatar asked Feb 27 '19 14:02

Shawnas


2 Answers

nuget.exe doesn't support packing PackageReference projects, and SDK projects are always PackageReference.

You should pack using either dotnet pack or msbuild -t:pack

like image 114
zivkan Avatar answered Oct 16 '22 05:10

zivkan


To target Multiple frameworks with nupsec xml attributes in the csproj SDK style file. Add this TargetFrameworks(with an 's'), back in the csproj:

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

Edit the manifest, add these lines in the ProjectGroup that defined TargetFrameworks:

<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>

Build the project, and the dll's go into their respective directories, the nuget get's built with source files for both target frameworks.

like image 32
OzBob Avatar answered Oct 16 '22 07:10

OzBob