33
votes

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!

8

8 Answers

52
votes

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>
30
votes

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

7
votes

You need to follow this procedure.

1. Update-package

2. Update-Package -reinstall

3. Restart visual studio.

5
votes

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.

2
votes

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.

2
votes

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

Get-Project -All | Add-BindingRedirect
1
votes

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.

-3
votes

For me rebuilding the project solved the issue. Right click on the Project -> Rebuild.