ChatGPT解决这个技术问题 Extra ChatGPT

Nuget Packages are there but missing References

After branching in TFS, VS2015 Update 2 has missing references to all Nuget packages. Package restore says "All packages listed in packages.config are already installed."

I could manually add references to all of the packages in the \packages folder but why isn't VS already checking there?


S
Sam

You need use the NuGet command line in the Package Manager Console:

Update-Package -reinstall

to force reinstall the package references into project.

NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project. For example, if a package has added some reference DLLs or other files in your project, if you delete any of these files, they will not be re-added when restoring this package. This may cause the your project to not be able to find the missing dependencies when building.

So use the "Update-Package -reinstall" command to force reinstall the package references and content files into project.


You can reinstall specific packages as well if some, but not all of them, have broken references. Look at the diff on your .csproj file after reinstalling to figure out what needed to change. For me it was the HintPath for one package. We had moved our .packages folder one level up to be shared between different repos but this project wasn't updated.
Does this install the latest version of each package, or the version originally installed (whether it is broken or not)?
@mrtumnus, the version originally installed.
Update-Package -ProjectName MyProject -reinstall for a specific project, made the mistake of running this without the project protocol
Project Rebuild is what solved the issue for me. My intention was only to restore the packages and never to install or re-install. Another developer installed the packages to the project and committed the changes. When I got latest I got the updated packages.config file. So all I needed was to restore those packages (as directed by the packages.config file). So VS correctly reported missing references before I did a restore. However even after a restore VS continued to report missing references. However when I built the project it built fine and the warning on references disappeared.
p
pabben

This worked for me:

Unload proj from solution

Edit csproj file and delete nuggets entries from csproj file (ItemGroup).

Reload proj


Thank you, that solved my problem too, but I did a "Update-Package -reinstall" as well, just in case
Thanks a lot. After the last step of restoring to the csproj file just deleted NuGet entries, all the missing references loaded correctly.
For me it happened when I moved one of my existing projects to a nested directory. So all nugets got messed up and even .NET DLLs stopped loading correctly. Solution was same for me. Please note that nuget package related information can be present at three locations which you need to delete. Their x-path is as following - 1. Project\Import 2. Project\ItemGroup\Reference 3. Project\Target\Error
s
stefano

as found for VS2013 by Shivam (https://stackoverflow.com/a/46763556/1034160) , my solution in VS2017 was to clear Nuget cache from: Options -> NugetPackageManager -> Clear All NuGet Cache(s)


M
Madan Kumar

If you cloned the project from a git repository and if the folder created while cloning has a '%20' in it. Then rename folder, get rid of '%20'. This should help to find the package dll's within the project.


Tried all previous answers, and shamefully this was the reason. Percent encoded characters should be replaced entirely, reference: w3schools.com/tags/ref_urlencode.asp
S
Siddharth B

Go to ->

Tools -> Nuget Package Manager -> Package Manager Settings Under Nuget Package Manager -> General Tab Do Clear Cache Restart Visual studio and Restore all Nuget Packages. This will refresh all the references.


S
Sotabound

I have had to recently add a Project to a very large Solution that contains multiple NugGet packages from multiple sources. My solution has been to run the Update-Package -reinstall in the Package Manager Console. Upon completion, all of the existing Projects will get an update. If you are using GIT, I recommend going into your Team Explorer and Undo all of the Changes to the Other projects that were updated, however keep the Changes for the new Project. Your references will be there and your "using" statements will not have that annoying squiggly red lines:)


Z
Zenobia Panvelwalla

One solution that worked for me is:

Go to Tools > NuGet Package Manager > Package Manager Settings. On the left pane, click on Package sources under Nuget Package Manager. Then ensure you have these settings:

https://i.stack.imgur.com/lsmgq.png

And then restart VS and Restore the packages.


M
MX313

I cleared my nuget cache after having an issue trying to install a package and experienced this issue... all my packages were there but reference errors everywhere. I was also unable to uninstall/reinstall a package and nuget console commands did not work either such as Update-Package -Reinstall -ProjectName Your.Project.Name. Nor did manually attempting to remove them from the csproj file as well as manually adding them by browsing directly to the package .dll's via 'add reference' on the solution menu tree in the ide.

Luckily I had backed up my entire project folder that morning via an outright .zip. I was forced to update my VS 2019 version to latest (Version 16.10.1 at time of this) and then restore to my backup and was fixed.

I will never clear the nuget cache again


J
Jagram singh

Right click on project, click unload project. Right click on project, click edit csproj file Remove below tag name from cproj file and save .............. Right click on project and ReLoad project