Glen Thomas
Glen Thomas

Reputation: 10764

Nuget package installed but references not resolved

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!

Upvotes: 49

Views: 81666

Answers (9)

floretti
floretti

Reputation: 55

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).

Upvotes: 0

M. Hamza Rajput
M. Hamza Rajput

Reputation: 10296

You need to follow this procedure.

1. Update-Package -reinstall

2. Restart visual studio.

Upvotes: 6

bbsimonbb
bbsimonbb

Reputation: 29020

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.

Upvotes: 0

wilmol
wilmol

Reputation: 1940

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.

Upvotes: 3

codeMonkey
codeMonkey

Reputation: 4845

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

Get-Project -All | Add-BindingRedirect

Upvotes: 3

MaC
MaC

Reputation: 301

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.

Upvotes: 6

Shivam
Shivam

Reputation: 41

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.

Upvotes: 3

CAOakley
CAOakley

Reputation: 1202

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>

Upvotes: 73

Glen Thomas
Glen Thomas

Reputation: 10764

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

Upvotes: 38

Related Questions