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

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)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)