git_gud
git_gud

Reputation: 689

nuget doesn't recognize installed packages

I have a C# project on Git that uses libraries from NuGet. Everything works fine, but when I pull on a fresh new machine and open the solution in Visual Studio it won't compile because of broken references. If I click on the references under the project I can see the classic warning sign with the yellow exclamation mark.

Nuget restore won't do anything (and I still haven't found any use of this feature...), files repositories.config are fine. If I right click on solution and then 'Manage NuGet packages for solution' no installed package is shown.

To this day I solved it this way: run

Install-Package package_name

it says:

'package_name' already installed.
My_project already has a reference to 'package_name'.

...and after that it shows the packages on the Manager, already assigned to the correct project.


NOTHING HAS BEEN CHANGED in the code ANYWHERE, I can see that because there are no differences on Git.

I have to do it only once on new machines, but it's really annoying. Any idea?


NuGet version: 2.8.60318.667


UPDATE 27/07

I tried the procedure from scratch on another PC, with windows 10, and everything works... same version of Visual Studio, NuGet, etc... I'm baffled

Upvotes: 27

Views: 43500

Answers (7)

marcolauro23
marcolauro23

Reputation: 31

I just downgraded the package version and then re-install the version that is supposed to show and it fixed the problem. Hope this helps

Upvotes: 0

Austin B
Austin B

Reputation: 190

Even after you've installed it at the Solution level, depending on your default you may have to pick which projects you want it to be available in. That was my problem.

enter image description here

Upvotes: 0

Piku Shrivastav
Piku Shrivastav

Reputation: 129

I experienced this issue today, and upgrading to the latest version of VS 2017 (15.8.7) didn't help at all.

Check your packages.config file(s) to see if your packages tag looks like this:

<packages xmlns="urn:packages">

If it does, remove the xmlns attribute so it's just:

<packages>

That fixed it for me!

Upvotes: 2

gargmanoj
gargmanoj

Reputation: 123

try removing your package from below nuget cache folder so that NUGET is forced to download from source

C:\Users\<< your user name >>\.nuget\packages

Upvotes: 2

Kemal G&#252;ler
Kemal G&#252;ler

Reputation: 614

I have solved this problem. Follow this steps

  1. In Visual Studio, click Tools > Extension and Updates.
  2. Navigate to Online, search for "NuGet Package Manager for Visual Studio" and click Update.
  3. (If there is no button Update, navigate to Updates > Visual Studio Gallery, find the "NuGet Package Manager for Visual Studio" and click Update.)
  4. Then restart Visual Studio.

Upvotes: 2

Katana
Katana

Reputation: 421

This is probably because of the incorrect path of the .dll in your .csproj. The package restore downloads the packages to the local directory. It doesn't change the reference path of the assembly in the .csproj, meaning that the project will still try to locate dlls on the local directory. The yellow mark means the project is unable to locate the assembly.

Unload the project, right click on project and select "Edit .csproj", and verify the path of missing dlls. For example - If you have NUnit,

<Reference Include="nunit.framework">
      <HintPath>..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>

verify if the dll is present inside "\packages\NUnit.3.6.1\lib\net45" directory.

Upvotes: 11

rjso
rjso

Reputation: 1614

From the top of my head I can think of a few reasons the packages are not being downloaded, ideally you would have to share a few more details.

First the install-package command won't work. Your packages are already installed VS is just unable to download them, so it makes sense that you are getting that error.

  • First and foremost is this a public package hosted in nuget.org like System.MVC.Web? Because if this is in a new machine, using a private nuget server, you need to configure that source in Tools > Options > Nuget Package Manager > Package Sources. (See https://learn.microsoft.com/en-us/nuget/tools/package-manager-ui for more details)
  • Check if you have added the folders to your git repo but at the same time set the exclusion for its contents. To check that when you do a clean checkout see if the folders exist but are empty. If thats the case just remove the folders, the git ignore should do its job from now on, and everyone new clone will do the proper check.
  • If the two above which are the most likely ones to be the reason do not work. Try and restore the packages from the Package Manager Console and update your post with the details.

You can open the Package Manager Console and type:

Update-Package -reinstall

or

Update-Package -reinstall -Project YourProjectName

FYI there's comprehensive document from Microsoft - https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore - on the multiple ways of restoring nuget packages

Upvotes: 9

Related Questions