Popplar
Popplar

Reputation: 279

Nuget Restore creating packages folder in a different location

I have a solution A which contains a class library, it has got a package.config. When I use Nuget Restore option, it recreates the package folder correctly and the references are ok. The problem comes when in another solution B, I add the project A and when I try to Nuget Restore, it creates the packages folder in the solution B directory and project A cant find the missing references. How can I make solution B to restore the packages needed for project A in project A directory?

Upvotes: 2

Views: 2530

Answers (1)

zivkan
zivkan

Reputation: 15091

TL;DR: Try running Update-Package -Reinstall from the Package Manager Console.

The only way I know for this to happen is when a project that uses packages.config for NuGet references is moved to a new directory with a different relative path to the solution. packages.config is basically "non-integrated" package management. Anyone using .NET since the beginning will remember when there was no NuGet and you'd need to add assembly references directly to dlls. packages.config automates this, but means that when the path to the solution packages folder changes, the references are no longer valid. NuGet doesn't know this and always restores to the solution packages folder. So, you need to update the project to point correctly to the solution packages folder. You can do it manually by editing your project file, by uninstalling and re-installing all the packages one-by-one, or use PMC's Update-Package to do it.

PackageReference doesn't have this problem, as the path to the restored packages is not stored in the project, so even if your project moves around, worst case all you need to do is restore again, but often even that's not needed. So, I recommend you migrate from packages.config to PackageReference if you can, but see the docs because there are package compatibility issues to be aware of. Basically, if you use packages with content that gets copied into your project on install, you need to stick with packages.config. Otherwise PackageReference gives a better experience to almost everyone else.

Upvotes: 1

Related Questions