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

隐身守侯 提交于 2020-08-03 14:08:17

问题


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.


回答1:


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)




回答2:


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




回答3:


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.




回答4:


Actually I just solved the problem on my end. Nuget may not find hidden dll. Here is my solution:

  • Build the project;

  • Show all files in visual studio so you can see the hidden files, so that you can see the dll under bin folder;

  • Right click, open folder in file explorer, then copy it to current folder let them replace/ Or unhidden the files;

  • Do "Nuget Pack" again.



来源:https://stackoverflow.com/questions/45815070/error-nu5012-nuget-pack-unable-to-find-path-bin-release-myproject-bin-releas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!