Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet CLI throw error Unable to find .nupkg

I try to build a package using NuGet CLI. I run next command :

.\nuget.exe pack D:\projects\CloudStorage.Client.csproj -OutputDirectory D:\packages -Build -Symbols -Properties Configuration=Release;

But always get next error:

Error NU5012: Unable to find 'Autofac.4.9.4.nupkg'. Make sure the project has been built.

But the solution is built.

I'm using the latest version of NuGet (v5.2.0)

In bin/Release folder Autofac is present or I don't understand correctly of the difference between missed '.nupkg' and present assemblies?

enter image description here

Also for the mentioned project, there are present CloudStorage.Client.nuspec file


This issue was detected when I updated one nuget package(https://www.nuget.org/packages/Z.EntityFramework.Extensions/) in solution that requires now SemVer 2.0.0 package... In order to build it, I upgrade Nuget to 4.3.0+ version. The result is above.


Project nuspec content:

<?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
       <metadata>
           <id>CloudStorage.Client</id>
           <version>$version$</version>
           <description>CloudStorage Client</description>
           <authors>MyTeam</authors>
           <tags>$branch$</tags>
       </metadata>
    </package>

UPD

I've created test project, where include Autofac 4.9.4 and try to build pack for it. It was successfully created. From console I see that for Autofac was copied all 3 files to bin folder .pdb, .dll and .xml files... while in my "problem" project only .dll is copied.

like image 759
demo Avatar asked Nov 01 '25 07:11

demo


1 Answers

I guess that the root cause of the issue is that your project is not in solution folder.

The hint paths in your xx.csproj file should be an absolute path like: <HintPath>C:\Users\xxx\source\repos\PackTest\packages\Autofac.4.9.4\lib\net45\Autofac.dll</HintPath>

instead of normal relative one:

<HintPath>..\packages\Autofac.4.9.4\lib\net45\Autofac.dll</HintPath>
  1. When you use command like nuget.exe pack D:\projects\CloudStorage.Client.csproj -build, it will call msbuild.exe to build the project and then use nuget.exe itself to create the package. Msbuild is build engine of VS, so it recognizes the xx.csproj file well, and it get the necessary assemblies from correct path. So the build succeeds.

    But somehow nuget.exe can't recognize the hintpath element, and since this project is packages.config format, during pack process, it will always try to find the xx.nupkg files from the packages folder in Solution folder.

  2. Normally the project folder and packages folder are in solution folder, so it works well. But since your project folder(in your situation its name is projects) is not in Solution folder, nuget.exe won't know where to find it. That's why the error message Unable to find 'Autofac.4.9.4.nupkg' occurs.

And that's why the build succeeds but we can't create the nuget package.

Here are workarounds:

  1. Create a nuget.config in D:\ next to the projects folder.

Its content should be:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="D:\PackagesForThisProject" />
  </config>
</configuration>

And then copy the packages folder from Solution Folder to D:\ , rename it to PackagesForThisProject.

Then you can create the package successfully.

  1. Or you can Migrate the packages.config format to PackageReference.
like image 67
LoLance Avatar answered Nov 02 '25 22:11

LoLance