0

We have a number of .NET Framework projects with a "nuget pack MyProject.csproj" command in the post-build step. We have been using VS2010 (:O I know) until now, and it has been happily spitting out nupkg files.

We recently updated our build tools to the 2019 version (running the new version of varsall.bat before calling msbuild), and the "nuget pack" command now fails:

Error NU5012: Unable to find 'MyProject.dll'. Make sure the project has been built.

What I've tried:

  • Adding a "nuget spec" step before packing
  • Upgrading the nuget CLI executable to the latest version
  • Updating from packages.config to PackageReferences
    • This allows you to use MSBuild -t:pack. However, two issues:
    • When running this in the post-build step on my machine, it starts dozens of cmd & MSBuild processes and pegs my CPU.
    • Our developers are stuck on VS2017 for now, but the 2017 build tools are no longer available for our build server (so we use 2019). The 2017 & 2019 installs put MSBuild in different locations. We could set path variables for all the machines, but that seems brittle.
  • I'm playing with upgrading one of the projects to the new csproj format, but it is rather involved. Upgrading all of our projects will be an effort all its own, and I'm still exploring the ramifications.

Is there something simple I'm missing which will allow this to work without large modifications?

Joe Schrag
  • 855
  • 8
  • 23

2 Answers2

1

Error NU5012: Unable to find 'MyProject.dll'. Make sure the project has been built.

This message indicates that the nuget.exe can't find the output assembly. So you must make sure the assembly is created successfully.

And one point you need to take care, normally we use command like nuget pack foo.csproj -Properties Configuration=Release to pack the assembly built in release mode. If you use command like nuget pack xx.csproj in post-build-event, no matter which configuration you use msbuild to build the project, nuget will always try to find the assembly in ProjectDir/bin/debug.

So when you deploy the project to remote server without bin and obj folders, if you try to use command like msbuild xx.csproj /p:Configuration=Release, the build is in release mode while nuget.exe will search the bin\debug instead of expected bin\release. You should check if you're in same situation.

Why does NuGet pack break with VS2019 build tools?

This issue is not about the build tools package. Since the error message you got came from nuget. Msbuild just help call the nuget.exe, and the cause of the issue is nuget.exe can't find the needed assembly by one specific path. Please check if the path in the error message is right, and then check if the assembly is in that path.

LoLance
  • 25,666
  • 1
  • 39
  • 73
0

I also ran into the same issue during our TFS upgrade to Azure Devops. The new Nuget task doesn't have the switch for -Build. The fields in the Nuget task screen for Pack also doesn't allow you to add this switch, that's why it's complaining about not finding the dll or the output of the build. I modified the nugetpack.js file on the agent's task folder to test the theory and now the pack options build successfully.

This is the line I added to the js file (towards the bottom of the page): nugetTool.arg("-Build");

what would be nice is to have this option represented as check box to cover if there is use case to call Nuget pack without -Build switch