45

I have a multi-project solution with Prism Nuget packages installed in several projects. I then attempted to add a Prism Mef extensions package to one of the projects using the Nuget Package Manager UI (I have already added it to one of the other projects).

The first time I attempted to add the package, it failed to install one of the dependencies, no specific error reason, just "failed". So, I installed it a second time, all seemed to be fine, no errors reported, but a few of the references did not resolve.

So, I uninstalled the package and all dependencies and installed it again. Again all appeared fine, but more references do not resolve.

I have tried uninstalling and installing the package more times but get the same result every time now.

I have had this problem many times and I know its not specific to the Prism package as I've had it with loads of different packages.

I think its just a major bug with Nuget, but I'm hoping somebody will know an easy way to fix it. I think I usually have better success with the Nuget console, but I find it more effort to use.

I've done some searching online and not really found a good explanation of the cause of the problem or a way to resolve it.

Somebody at work completely refuses to have anything to do with Nuget as he has so many of these issues, but I am determined to make it work!

Glen Thomas
  • 10,190
  • 5
  • 33
  • 65

9 Answers9

67

Within the Package Manager Console run the following command:

Update-Package -reinstall

This will reinstall each nuget package within that project which should resolve any missing references.

If you know you're missing a specific reference:

Update-Package -reinstall <Package-Name>
CAOakley
  • 1,142
  • 1
  • 10
  • 8
  • 1
    You can see in the question that I already tried reinstalling the required packages. The problem was caused by a bug in Visual Studio where the references are not resolved correctly. – Glen Thomas Nov 23 '16 at 23:31
  • my issue was described here: https://developercommunity.visualstudio.com/content/problem/502713/vs2019-nuget-package-installed-but-not-recognized.html https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference – juFo Feb 11 '20 at 08:54
34

I just closed Visual Studio and reopened it and references are resolved...!

Glen Thomas
  • 10,190
  • 5
  • 33
  • 65
  • 10
    Visual Studio and its caching issues are very annoying – Alexander Nov 16 '17 at 14:28
  • After spending some hours to resolve this... It's 2019 but looks like the old and ugly microsoft solution guideline works: when something not work as expected just re- do, start, install and it gonna work. Arrgh – Dankó Dávid Jun 03 '19 at 11:07
  • 1
    I had a similar problem just installing a single simple nuget package to a project. For me, closing and re-opening didn't seem to help, so in the end I used the "Add Reference" - "Browse" to manually locate the package DLL under the "packages" folder in my project, and add the reference to it. After that it worked fine! – Loophole Mar 30 '20 at 23:34
  • I had this issue but restarting and re-installing didn't work. For me, all I needed to do was compile the program, and the issue went away. – NiallUK Jun 21 '22 at 08:35
6

You may want to check the .NET version of the package vs. your project.

I had an instance where my project was .NET 4.6.1, and the package I was attempting to install was using version 4.6.2. After updating my project to the same .NET version, the reference showed up.

MaC
  • 191
  • 2
  • 4
6

You need to follow this procedure.

1. Update-Package -reinstall

2. Restart visual studio.

M. Hamza Rajput
  • 7,810
  • 2
  • 41
  • 36
  • Reinstall was the key for me. I had forgotten to update my package references after upgrading my .net framework version – TabsNotSpaces Sep 01 '20 at 19:30
  • 2
    Step 1 literally updates all of your packages to the latest version. This caused tons of reference errors in my project. Just use `Update-package -reinstall` to install the same version. [reference](https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages) – tacticalmovephase Jul 20 '21 at 16:25
3

Delete all the <assemblyBinding> references from your .config file, then run this command from the Nuget Package Manager:

Get-Project -All | Add-BindingRedirect
codeMonkey
  • 4,134
  • 2
  • 31
  • 50
  • for me, closing VS, deleting the s from my .config file, and re-opening solved the issue (I was going to follow your instructions, but already had VS closed, and didn't need to run Get-Project... upon re-opening). strangely, the nuget package manager doesn't list the packages, but they're now showing up in the References! I'm not sure how that works >_> VS is so mysterious sometimes... – Ben Jul 22 '19 at 12:33
3

This is how I fixed it.

I was working on a legacy .NET framework project (using <Reference Include... rather than PackageReference). The .dlls were referenced with a relative path that wasn't being resolved.

Fixed by changing to absolute paths, building, then changing back to the original relative paths.

For example:

    <Reference Include="My.Package">
      <HintPath>..\..\packages\My.Package.dll</HintPath>
    </Reference>

Changed to:

    <Reference Include="My.Package">
      <HintPath>C:\Users\will\Documents\MySolution\packages\My.Package.dll</HintPath>
    </Reference>

Then built and changed back to the relative path and the build still worked.

wilmol
  • 1,429
  • 16
  • 22
2

I recently encountered this error on visual studio 2012, solution for me was to delete .nupkg file from nuget cache. Nuget cache location can be found from nuget settings > general > browse.

Note: I did not clear cache, I just deleted a specific file from cache directory and reinstalled the nuget package.

Shivam
  • 31
  • 3
0

In our case, on one machine VS was holding onto an old version of a dependency, so references to newly added methods in the dependency were not resolving (even when package manager was reporting the latest version installed). The solution was to restart visual after uninstalling the dependency, then install again.

bbsimonbb
  • 27,056
  • 15
  • 80
  • 110
0

I tried all the other options but nothing solved my problem. What solved it was going to the package information in the nuget website and checking what versions of .Net Framework the different versions of the package worked with.

Unfortunately the latest stable version of the package didn't have my .Net Framework version listed so I uninstalled it and installed the 2nd latest version, which had my .Net Framework version listed and it all worked as expected.

Simple but unexpected (at least for me).

floretti
  • 31
  • 5
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/34605284) – ryanwebjackson Jul 02 '23 at 12:52