24

I recently migrated all my Visual Studio 2013 projects to Visual Studio 2015 and followed the steps documented in this article by Nuget to make sure that automatic package restore is still working, in short

  • I deleted the Nuget.exe and Nuget.target files from source control and disk
  • I updated all project files and deleted the sections related to Nuget

I'm experiencing a problem when I'm updating Nuget packages, it is not updating the project references to point to the newest dll versions. I can see that the newest packages was installed though. This problem is also not related to specific packages.

Has anyone else experienced a problem like this?

RBT
  • 24,161
  • 21
  • 159
  • 240
Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96
  • `Update-Package -reinstall` reinstalls the package, but installs the newest version of all dependencies that package has. Prepare for conflicts..;) – Wogelberg Dec 13 '16 at 09:49

8 Answers8

33

NuGet package restore does not modify the project files. It just downloads and extracts the NuGet packages to the packages directory.

If you are trying to edit the packages.config file and then have the project's updated you would have to use the Package Manager Console and run:

Update-Package -reinstall

Which will uninstall and install the packages again and update the project's references.

Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • I'm experiencing the problem after the packages were restored and I'm updating the packages to a new version. – Andre Lombaard Sep 16 '15 at 05:41
  • OK. It was not that obvious from your question that the problem was that the references were being made directly to the assemblies without using NuGet. – Matt Ward Sep 16 '15 at 10:34
  • Yes, also only found that out after doing a proper investigation. – Andre Lombaard Sep 16 '15 at 10:42
  • Check your Build output logs carefully because I faced with similar problem when my project file referenced to the MSbuild target file which path was incorect after the update. And build was failing before restore packages. – Nazar Mandzyk Jul 31 '17 at 14:09
  • One other thing to note: if you add a nugget package via the UI (right-click-project ->manage packages), it will add the reference for you. If you edit packages.config by hand, you need to run Update-Package -reinstall. Thank you Matt! – Steel Nation Aug 15 '18 at 23:21
  • Thanks Matt, this was the solution for me – JFM Feb 10 '20 at 08:24
7

We realized that some of our junior developers only installed the required Nuget packages for ONE project in the solution, they then added references to the required dll's for all other projects by browsing to the physical location of the dll's on disk. This obviously caused the problem because only ONE of the projects in the solution contained entries for Nuget packages in it's packages.config file while the remaining projects in the solution contained none.

When all packages were updated using the Update-Package command only the ONE project containing entries in it's packages.config file were updated with the correct project references.

Even though this is not a Nuget bug and rather a problem caused by inexperience, I logged an issue with Nuget to see if they can improve the software to prevent these types of problems.

Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96
4

So I recently had a very similar issue as well, unfortunately uninstalling and reinstalling did not work. Hopefully this helps anyone else as it was very frustrating.

Steps:

  1. go to or launch the quick launch feature.
  2. type package manager
  3. select "tools->Nuget PackageManager-> Package Manager Settings"
  4. In the options window that pops up. click "Clear All Nuget Cache(s)"
  5. Right click solution and select Restore Nuget Packages.

Hope this helps.

jtslugmaster08
  • 182
  • 1
  • 16
  • 1
    In case you find it difficult to trace quick launch feature visually in the IDE then simply press `Ctrl`+ `Q` key combination as a shortcut. – RBT Jan 31 '18 at 08:01
  • 1
    `Clear All Nuget Cache(s)` option has been removed from Visual Studio(VS) 2015 which resurfaced in VS 2017. You can checkout how to do it from command line [here](https://stackoverflow.com/a/34935038/465053) in case you are using VS 2015 in your development environment. – RBT Jan 31 '18 at 08:02
3

I was facing an issue with NuGet package of Newtonsoft.Json as shown below:

enter image description here

I tried all possible solutions but none of the below mentioned ones worked:

  • Cleaning solution
  • Rebuilding solution
  • Clearing NuGet package cache

Finally I realized it had something to do with .NET Framework version targeted by my C# project. There was some mismatch it seems. The moment I upgraded the .NET Framework version of my project to latest, the Newtonsoft.Json package dependency and its reference came alive instantly.

RBT
  • 24,161
  • 21
  • 159
  • 240
  • 1
    Yes, turns out, if the project's Framework version is less than what is in the package, the reference just silently doesn't get added. – Mikhail Orlov Oct 10 '18 at 11:39
2

Something I just noticed, and I'm not sure if this will help you or anyone else reading this, but this issue literally wracked my brain. The problem was that I was installing packages that I had created myself using NuGet Package Explorer on Windows.

It turned out that, I believe after updating NuGet Package Explorer, it was no longer putting DLLs that I included into the lib folder. Once I started manually adding the lib folder back into the package within Package Explorer, and then uploading to NuGet and reinstalling in the consuming project, that the reference would once again start to appear.

I'm not sure what caused this behavior - it could have been my own fault, but I literally just now figured this out - and consequently have to go back and re-do a whole bunch of NuGet package goodness that I've done over the past month. OUCH.

Hope this saves someone at least an ounce of pain.

joelc
  • 2,687
  • 5
  • 40
  • 60
1

None of the above worked for me.

What did work, was to edit the project file directly and delete the existing reference. When I reloaded the project, the package then showed up in references as a Nuget package.

Kevin Finck
  • 317
  • 3
  • 6
1

I happened to come across the same problem. i tried all the possible solution but found the solution - just open the .proj file in an text editor and check the package Version and the HintPath in the Reference tag. Sometime there is an mismatch correct it then Visual studio will recognize. I hope everyone can save lot of time. Here is an sample to refer

<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
      <HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
0

Migrating to PackageReferences worked for me for the projects that allowed it. My Asp.Net project could not be migrated, so I resorted to manually adding the references to the .csproj file

Homer
  • 7,594
  • 14
  • 69
  • 109