How to resolve "NuGet package restore failed" in Visual Studio? - c#

I got an error
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
while building my solution. Package manager can't restore my 2 projects:
Unable to find project information for 'C:\(...)\MultiLinker.Courier.Dext.Model.csproj'. The project file may be invalid or missing targets required for restore.
In tools I allow package manage to download packages:

Ran into the same issue. In my case, it was because Visual Studio only had the Offline Package source and could not resolve the packages I needed. I added in the nuget.org source as shown below in the NuGet Package Manager settings and right clicked on the solution and selected restore packages. and it resolved the issue.

open Nuget Package Manager -> Package Source > Add https://nuget.org/api/v2

I might be forgetting some steps, but a crucial step for me to fix this was running nuget restore from the commandline (Trying to restore from Visual Studio UI was not sufficient for some reason).
I also added a plugins folder given to me by a teammate to my .nuget folder that supposedly makes it handle our credentials automatically, so if you are having this issue maybe that is something you are missing as well.

In my case it was my Company DevOps credentials being out of date
Account Settings > Change credentials in the dialog that opens

On Visual Studio Code (VSCode) this can be solved this way:
dotnet new nugetconfig

thank you it works fine
and solved all issues of nuget
by creating the new value in the setting of nuget
under tools > nuget package manger > package manger settings
nuget package sources
add new value nuget.org and https://www.nuget.org/api/v2/
then save and update you project
it will work

The nuget restore did not work for me but once I used nuget.org it worked just fine. This was the best solution for me.

Upgrading my out of date Visual Studio helped for me:
Help Menu: Check for Updates...

Related

The project references NuGet packages that are not on this computer

i'm getting following error when i build my solution in visual studio 2015.
but when i try to add that particular package then visual studio show it already added
Did you notice something? the version is different you need version 1.0.5 instead of 1.0.7
Open Nuget Package Manager and pick "Unistall" on this package, than istall it again. If this does not help you do next:
Unload project and remove all reference on this package from .csproj file
Remove reference on this package from Web.config (or App.config) if it there.
Remove reference from packages.config file
Install via nuget you package again.
Hope this helps you.
Right click solution in visual studio and select "Restore Nuget Packages", it will download the missing packages
Use the following command in the Package Manage Console:
Update-Package -reinstall -Project YourProjectName
It is by project, but this way is garanteed it works, at least in 100% of cases that happen to me.

Some NuGet packages are missing from the solution in Visual Studio Application

After pulling some code updates I found I got this message when building.
Some NuGet packages are missing from the solution.
The packages need to be restored in order to build the dependency graph.
Restore the packages before performing any operations
In solution explorer the references links displayed with a missing reference icon
I deleted the references Then at the package manager console a button appeared asking if I wanted to install the missing packages. However, this did not work.
I am writing this answer as I tried the below solutions but none of them worked :
Clearing the cache
Restoring or re-installing the packages
Changing the targetFramework
Updating the Nuget Package manager
Then I looked upon a dropdown list and it appeared the error was trivial. The package source was offline !! I installed VS2017 professional on my system and opened an existing project and found that multiple packages were missing. I tried everything I could, without looking at Package Source !!
Solution:
Step 01. Go to Package Manager Settings (Tools > Nuget Package Manager > Package Manager Settings)
Step 02. Check the Package Source(s). As you can see, the package source is here already downloaded SDK/nugets/packages. I don't know the reason but the online package source from nuget.org was missing from my system installation of Visual Studio.
Step 03. Install the nuget.org as package source and then 'Clear All Nuget Cache(s)' and then restore the packages. The error will go away.
Name: nuget.org ( or as you wish)
Source: https://api.nuget.org/v3/index.json
When I tried opening the project on its own , outside the solution, and buidling it I received the message.
One or more NuGet packages need to be restored but couldn't be because consent has not been granted. To give consent, open the Visual Studio Options dialog, click on the Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.
I granted VS the permission, then I ran at the package manager console
update-package -Reinstall
Click Ctrl+Q and write the name of the missing package and then click search for online NuGet package matching .
It will show menu click on browse that will give you the missing package click install ,uninstall or update.
It's possible that folder/zips content error during the first download so go to the Xamarin folder (C:/User/YourName/AppData/Local/Xamarin) and delete or rename or move out the folder of missing nuget or content the of zips folder.
Restart the IDE, your IDE download again the content. I tried this and it works.

'Newtonsoft' could not be found

I pasted the code from http://www.codeproject.com/Tips/789481/Bridging-the-Gap-between-Linqpad-and-Visual-Studio into Visual Studio 15. It tells me that 'Newtonsoft' could not be found. I open the folder "\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies" and found that the file Newtonsolft.Json.dll is already there. Could anyone tell me how to fixed problem?
Solution Explorer->Right Click on Project Name -> Click on Manage Nuget Packages -> Search for newtonsoft -> Click on install button
Go to Tools -> Library Package Manager -> Package Manager Console
and in the console just write Install-Package Newtonsoft.Json -Version 9.0.1
For me I had the package already installed but it was missing the references and it could not be added.
Helped me: in NuGet Package Manager to downgrade and upgrade Newtonsoft.Json
You have to get the correct NuGet package. From your link:
You can open the NuGet package manager in: Tools -> Nuget Packet Manager -> Manage Nuget Packages for Solution..
I had a similar problem and Google API's had a dependency on Newtonsoft.Json, not allowing me to uninstall Newtonsoft.Json and trying to reinstall.
Removing and and reinstalling Newtonsoft.Json will likely solve the problem, but in my situation, I had to go into Nuget Package Manager -> find Newtonsoft.Json -> select Options dropdown -> check "Force uninstall even if there are dependencies on it".
Checking that box allowed me to remove and subsequently reinstall Newtonsoft and the solution properly referenced it after.
I had the same problem with visual studio 2019. Simply restarting visual studio fixed the issue.
After restarting, the References list in Solution Explorer did show the "Newtonsoft.json".
Right click on the client project side and select Manage NuGet packages.
Then search for Newtonsoft.Json on browse and install.
If the class you are trying to use Newtonsoft is in client you must install the package for the client.

NuGet has problems with missing packages, how to restore?

When I try to compile my program I get the following error:
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.
Now when I right click on the solution and press
All packages are already installed and there is nothing to restore.
I tried manually reinstalling every package which didn't solve the problem, I tried reinstalling NuGet but that didn't help either and I even tried reinstalling visual studio.
I also tried moving the package folder from the tfs folder to overwrite my package folder but that didn't solve anything. I also tried redownloading them with this package missing, that didn' t solve the problem either.
Anybody know how to restore the nuget packages?
Use Package Manager Console in Visual Studio to run this command.
1.This will restore all packages from solution
nuget restore YourSolution.sln
2.If you want to reinstall the packages to the same versions as were previously installed
Update-Package -reinstall
Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board. They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted. a "NuGet Get-Packages -Force" option would really save their bacon. The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet. Even clearing the cache via VS is useless.
I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.
When the project file was initially created, it seems VS2019 added the following into the project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.
Anyway, after removing those lines VS restored the packages and built the solution correctly again.
It's probably a good idea to clear the Nuget Cache by deleting the contents within this directory: C:\Users\{your_username}\AppData\Local\NuGet
All you need is that:
Open the Package Manager Console and run this command: Update-Package -reinstall
P.S: VS2017 and above NuGet Package Manager is included with Visual Studio, no need to install anything else.
The problem with the functionality of the NuGet package can also be caused by the fact that NuGet package is requiring certain dependency that the project does not meet.
NuGet package can have a declared dependency in Dependecies section, e.g. .NETFramework,Version=v.4.6.2 while the project is targeted to an older version (Target framework: .NET Framework 4.6.1.).
Instead of the NuGet system notifying the user of this fact, the project simply does not compile.
In my case, I have different Nuget configurations, and somehow the HintPath in the project file didn't fit.
Maybe you should check if the HintPath leads to the right NuGetPackages folder.
You should also check the following entries at the top of the file:
And at the bottom of the file:
All these paths should point to the right NuGetPackage folder in your file structure.
In my case the problem was solved by deleting the "obj" folder(s) and then rebuilding the solution.
The "obj" folder had several NuGet related files that still referred to version 0.0.2 of a package while all projects in the solution were already using version 1.0.0 of that package. Building the solution failed with the error message "package with version 0.0.2 could not be found". The solution with build folders included was recently copied from another machine.
Well it's probably a bad way but I found that it works if I just delete the line
http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
from the project.csproj , not sure if this is going to cause problems later on but it works for now.

NuGet fails to find existing package

How it's possible that NuGet's Install-Package fails with Unable to find version 'x' of package 'y' when that exact version is released as NuGet to the official repository and it shown on the https://www.nuget.org/packages/y page.
Here is specific sample with nuget.org content and NuGet Install-Package command output.
UPDATE. Package sources are set to defaults (from nuget.org). Actually, you can see the issue just by running Install-Package Log4Net.Async -Version 1.3.0.
UPDATE 2. I want to highlight that it's not about some developer's machine - the same things happen on Visual Studio Online Hosted Build Controller.
UPDATE 3. Here is how NuGet tries to load package and it looks like NuGet API just broken, because all these requests fail with the error below.
Resource not found for the segment 'Packages'
Also NuGet produces a strange output on NuGet API calls that issued at VS search packages stage, please see here: http://pastebin.com/qveadrZB.
NuGet currently has some service issues related to search and package restore functionality. It is possible this is the cause of your package restore failure.
If other dev machines are working OK, it's likely they have access to a cached version of this package.
Clear your NuGet cache under options -> NuGet Package Manager
I know this thread is very old, but someone who has this problem like me in these days, find my solution for solving such problem here.
I've installed Visual Studio 2012/2015/2017 parallel, and 2012 failed with "package not found error".
So I take a look in the NuGet-settings in VS2017 and found the following package resource:
https://api.nuget.org/v3/index.json
I just added this location to the package resources and vĂ²ila, the searched packages where found and installed (in my example the HtmlRenderer).
But be careful with compatibility to Framework 2.0! This setting breaks maybe the functionality to version 2.0!!
Hope this helps someone sometimes somewhere.
Greetings
I'm a latecomer to this thread... I'm in Visual Studio 2017 - 15.9.4
I got this error today trying to pull from my private DevOps NuGet feed
CONTEXT:
the first time I called Install-Package everything worked, but, my NuGet was not assembled right, so, I re-published the NuGet pkg, and
when I tried to update my project that was consuming the pkg, that's
when I got the failure)
Switching my Package Source to "all" alleviated the problem.
After 4 hours struggle I found solution here
https://www.grapecity.com/componentone/docs/uwp/online-getting-started/config-nugetpackage.html
Tools > Options > NuGet Package Manager > Package Sources. > Click add button and add following one by one
nuget.org
https://www.nuget.org/api/v2/
GrapeCity
http://nuget.grapecity.com/nuget
NuGet settings in Visual Studio
Right click on references in your project
Manage NuGet Packages => All
Uninstall affected packages
If this does not resolve the issue, try to remove it from the NuGet config file located at
C:\Users\UserName\AppData\Roaming\NuGet\NuGet.config

Categories

Resources