Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error NU5012 - nuget pack unable to find path (/bin/release/MyProject/bin/release)

I'm trying to update my nuget package by running the command nuget pack -properties Configuration=Release but this gives me the following error:

Unable to find 'bin/Release/{project-name}/bin/Release'. Mae sure the project has been built

I'm not quite sure why it goes to my Release folder and then continues to go down to another Release folder as this doesn't exist? I'm quite lost here, and I'm not sure what to do.

like image 564
Detilium Avatar asked Aug 22 '17 10:08

Detilium


3 Answers

TL;DR

For the new <Project Sdk="Microsoft.NET.Sdk"> .csproj file format, use dotnet pack to build NuGet packages, even if they target .Net Framework or if the project is multi-targeted. Run this from the directory containing your .csproj (and optionally a .nuspec)

dotnet pack MyProject.csproj -c Release

Note that by default dotnet pack places the output .nupkg in the /bin/Release folder, which is different from the current default folder where older nuget pack placed it.

I would suggest you don't create explicit .nuspec files for the new .csproj formats, since most settings can be set in the "Packages" tab of the new Project format. However, if you do have a .nuspec, then dotnet pack will also combine any .nuspec file matching the project name, allowing for the $ symbol substitution from the version and metadata set in your .csproj.

More Detail

I also experienced this problem - in previous versions, I typically use to use this approach to pack against a .csproj with the .nuspec file of the same name, so that I can use all of the $ tokens like $id$, $version$.

However when attempting this against the newer <Project Sdk="Microsoft.NET.Sdk"> csproj formats:

nuget pack {MyProject}.csproj -Prop Configuration=Release

I received the same error (note the "duplication" of bin\release):

Error NU5012: Unable to find 'bin\Release{MyProject}\bin\Release\'. Make sure the project has been built.

And if I tried packing against a .nuspec containing symbols (NuGet Version: 4.7.1.5393)

nuget pack {MyProject}.nuspec -Prop Configuration=Release

I just get the unhelpful message because nuget isn't able to resolve the $ tokens automatically.

Value cannot be null or an empty string. Parameter name: value

However, by using dotnet pack instead of nuget

dotnet pack MyProject.csproj -c Release

I get to where I want to be, i.e. a multi-targeted NuGet package with the $ symbols in the .nuspec correctly synchronized from the .csproj (you can verify this by opening up the .nupkg file in e.g. 7zip and examining the final .nuspec file in the package root)

like image 195
StuartLC Avatar answered Oct 09 '22 13:10

StuartLC


I had the same problem on a multi-targeted project (targetting both net452 and netstandard2.0).

My fix/hack was to add 'TargetFramework=net452' to the list of properties passed to Nuget, and manually adding the netstandard2.0-output to the files-section in the .nuspec-file

Hope someone finds a better solution

like image 20
Rune Avatar answered Oct 09 '22 13:10

Rune


Part of Rune's answer (setting TargetFramework=net471 NuGet property)

and using NuGet version 4.9.1 (instruction here: https://stackoverflow.com/a/53614798/1813219)

was a way to go for me.

like image 1
Mariusz Ignatowicz Avatar answered Oct 09 '22 13:10

Mariusz Ignatowicz