23

i have the following setting:

  • nuget.exe Version: 1.6.21205.9031
  • Project A.csproj packaged into A.1.0.0.0.nupkg, and published to a LOCAL package repository hosted on my local IIS (My VS Nuget Extension i able to add the A-package to a new project)
  • Project B.csproj has a dependency to the A-package that i added with the VS Nuget Extension

Now, when i run

nuget spec

the B.nuspec is created.

Then i run

nuget pack B.csproj -verbose

but in the created B-package, their is NO dependency to the A-package. The nuget pack command tells me that it has found the packages.config file (which contains the dependency to the A-package), but then it says "Dependencies: None".

What am i missing? Could the problem be that the A-package can only be found in my local package repository? How can i make nuget.exe aware of this local repository?

Thanks a lot!

Matthew Marlin
  • 316
  • 3
  • 11
Schweder
  • 1,464
  • 2
  • 13
  • 19
  • I would love to know the answer to this problem as well. The documentation states that the nuget pack B.csproj step *should* include dependencies, but it does not for me. – Kevin Tighe Apr 08 '13 at 15:05
  • 4
    Still same problem here and none of the listed solutions work. – cbp Apr 09 '15 at 07:32
  • Looks like same issue I'm experiencing, just in my case one out of 3 dependencies actually _is_ included. – Jacek Gorgoń Jul 20 '15 at 17:05

5 Answers5

15

nuget pack needs to be able to find the packages folder in order to resolve dependencies (see http://nuget.codeplex.com/workitem/3097), either in the same folder as the .csproj (as long as there's a .sln file one level above it) or in a folder specified in NuGet.Config.

Rick Mohr
  • 1,821
  • 1
  • 19
  • 22
  • +1 I had customized the `packages` folder to `nuget-packages` in Nuget.Config. Renaming it back fixed the issue for me. – Wim Coenen Mar 25 '14 at 11:02
  • 11
    One would think NuGet would fail or at the very least emit a warning if it can't add a dependency to its list of dependencies as this leads to the generation of incorrect packages with incomplete dependency lists. I wish there was an option available to fail on such problems rather than "complete successfully" and leave the users of the packages to find out why things don't work for them. – Guillaume LaHaye May 10 '16 at 19:04
  • Link is broken since the site has moved, and issue 3097 on the new location doesn't seem to be related to this. I'd be very grateful you could find the same issue on the new location and update the link. – Richardissimo Oct 03 '18 at 08:49
  • You can still find the issue on Codeplex just click Issues at the top of the screen and search for ""Nuget pack" ignores dependencies from packages.config" Reposted the issue at https://github.com/NuGet/Home/issues/8643 – David Sep 30 '19 at 15:05
3

I think I may have figured this out...

Our library solution had Nuget Package Restore turned on. I turned off NuGet Package Restore, and after that the project dependences were included when I created the NuGet packages.

I'm not really sure why the dependencies were not included in the package when Package Restore was turned on, but oh well :).

Kevin Tighe
  • 20,181
  • 4
  • 35
  • 36
1

'Nuget.exe spec A.csproj' will create a very thin NuSpec file which won't have any dependencies. For our process use a powershell script to add the Project References and other dependencies from the project's packages.config to the <dependency> node in B.nuspec.

'Nuget.exe pack A.nuspec' will then be correct.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
wlscaudill
  • 505
  • 4
  • 6
  • 1
    Note that OP is using `nuget pack` with a .csproj file. This is designed to take dependencies recorded in the .csproj into account, both the ones added with nuget and any references to other projects in the same solution that have a .nuspec file. – Wim Coenen Mar 25 '14 at 10:54
1

Similar question was asked here, and the answer explains that:

The reason why these were causing problems is because NuGet looks for the solution level packages folder to decide which package dependencies to pull in (not quite sure how this determination is made). If the path to that packages folder is incorrect (as it would be if NuGet uses the wrong solution file), then it can't resolve the dependencies correctly. In addition if the packages folder is empty, it also cannot resolve the dependencies correctly.

I had the same problem and adding solution file to project folder (previously without solution) helped me to resolve the issue.

Community
  • 1
  • 1
1

The dependencies were missing for me because I didn't have the *.nupkg files in the packages folder for all the packages I was using.

This was pretty hard to track down, because the output of nuget pack looked like it was working:

Found packages.config. Using packages listed as dependencies

I had been using GitHub's Visual Studio .gitignore and only commented out the one line about "Package Restore" (because I wanted to commit my packages), but I should have commented out two. It should look like this:

# NuGet Packages
# *.nupkg
# The packages folder can be ignored because of Package Restore
# **/packages/*

Thanks to Rick Mohr's answer for linking to the CodePlex work item 3097, where feiling explains how the packages folder is used:

Since packages.config contains just a list of packages, and does not contain dependency relationship between those packages, nuget needs to access those package files to get the dependency info. That's why it needs to know the packages folder.

The dependency information that feiling refers to is inside the *.nupkg files. Once I changed the .gitignore and committed all the missing *.nupkg files, my TeamCity build server was able to successfully create my NuGet package with the correct dependencies.

jason_ruz
  • 2,135
  • 1
  • 20
  • 22
  • For nuget to assume the only dependencies of a project is other nuget packages is a big fail. Of course projects often have dependences on other projects in the same solution. – LarryBud Apr 02 '21 at 11:39