ChatGPT解决这个技术问题 Extra ChatGPT

Unable to Install Any Package in Visual Studio 2015

I've tried every package I could possibly find and none of them will install in my project. I've installed every update listed in the Extensions and Updates list that were available. When I attempt to install SendGrid for example, this is the result (as is the result with all other packages):

Attempting to gather dependencies information for package 'Sendgrid.6.1.0' with respect to project 'UI\MyApplication.MVC', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'Sendgrid.6.1.0' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Sendgrid.6.1.0'
Resolved actions to install package 'Sendgrid.6.1.0'
For adding package 'SendGrid.SmtpApi.1.3.1' to project 'MyApplication.MVC' that targets 'net452'.
For adding package 'SendGrid.SmtpApi.1.3.1' to project 'MyApplication.MVC' that targets 'net452'.
Adding package 'SendGrid.SmtpApi.1.3.1' to folder 'C:\Users\Keith\Source\Workspaces\MyApplication\MyApplication.MVC\packages'
Install failed. Rolling back...

I can't be the only one on the planet having issue with Visual Studio 2015 and the new and "improved" NuGet Package Manager.

UPDATE: Well, must be something odd in my solution because I created a new project from the VS2015 template (web) and the packages install just fine. When I find out the issue, I'll post the resolution in the event others run into the same problem.

UPDATE 2: Ok, it's not our solution. We created a new solution from scratch again (this has wasted a lot of our development time might I add), added a couple of packages (Identity, EF, SendGrid) and after checking the solution in to VSO, another developer performs a fresh creation of the branch and build errors occur. When I go to the NuGet packages for an individual project, it acts as though none of the packages I have added are available. Anyone else experiencing this?

Use VS2013 to add packages VS2015 is very problematic then just open in VS2015 and carry on using that

I
IAbstract

Closing and re-opening VS2015 resolves the issue.

It seems that in some cases, simply reloading the affected project will work.


This worked for me too, after I closed VS, nuked the 'packages' folder for the solution, and restarted.
This worked for me, although I had to close all instances of VS - closing just the affected one wasn't enough.
It seems so simple... and yet +111 votes! Worked for me too!
Why, Microsoft?!?! Why does this have to be the best answer (and the one that worked for me)?
I am not comfortable with the answer but it works, we need the "why"
K
KyleMit

tl;dr - Delete this:

%AppData%/Nuget/Nuget.config

Warning: If you had custom NuGet sources, this will remove them, and you'll have to re-add them.

Longer version:

You might have corrupted your NuGet config. Oh no :(

Nuget.config is a file used to keep track of all of the places that NuGet pulls from, as well as configuring other things. More likely than not, this xml file got broken somehow.

Go to this path: C:\Users\{{username}}\AppData\Roaming\

Delete Nuget.config

Restart VS for good measure

For reference: in the good days of 2017, your file should look something like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <activePackageSource>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </activePackageSource>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <!-- Others -->
  </packageSources>
  <packageSourceCredentials>
    <!-- secret stuff -->
  </packageSourceCredentials>
</configuration>

Thanks, that was a neat solution
This works for me as well, thanks Statue you saved my time.
Amazing coincidence. This post from a year ago gets edited right before my eyes right when I need the answer. Thanks!
Sorry to bump this, but mine had to be special and was so called "NuGet.Config", which was very specific on NTFS for me!
(Actually, turned out I didn't even need to delete the config at all. A restart of Visual Studio was required.)
A
Alejo03

I found a solution for this in my case, try to update the NuGet Package Manager.

To do this:

From VS, go to Tools -> Extensions and Updates Open the Updates menu option at the left, then select Visual Studio Gallery. If there is an update for Nuget Package Installer, it should show in the list to the right. Click Update Restart Visual Studio

This let me install packages without problem again.

Hope this helps!


I followed this, however there was no updates pending for Nuget. There was one for "Web Tools" and this resolved the "nuget configuration is invalid" error for me.
It probably wasn't the fact that you upgraded "Web Tools", but rather the fact that installing extension updates requires you to restart Visual Studio. Restarting worked for me.
Worked for me as well
In my case there was no update available, but I downloaded the latest version from dotnet.myget.org/F/nuget-vsix/vsix and it worked.
No update was available, so I uninstalled and reinstalled the "NuGet Package Manager for Visual Studio 2015". I verified I was then able to install NuGet packages again! :)
N
Nikolay Kostov

In my case updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers caused the problem.

Deleting bin, obj, and packages folders and restarting Visual Studio 2015 solved the problem for me.


Other solutions didn't work but this one did. Deleting 'packages' was the key for me
I don't know why deleting the packages could work, but it does! I hadn't updated anything though, I was just migrating from Visual Studio 2010 to 2015, and .NET 4.0 to 4.5.
Where can I find the 'packages' folder? I only have bin and obj.
T
Tom Stickel

In general closing and re-open VS 2015 fixed most problems I have ran across. Once I did need to run a repair on one of my computers.

However I was about to do this Closing and re-opening VS2015 resolved the issue for me I figured that I would instead right click on the project and Unload Project then right click and Reload project THEN Manage Nuget worked!


P
Paul Roub

You need to Clear All NuGet Caches; for this you need go to Options and click on it like this:

https://i.stack.imgur.com/6dUzy.png


Jesus, omg, you saved my life, I was getting crazy... I was always getting the error "Install failed. Rolling back...". Tried deleting the NuGet config file has the accepted answer told and also tried restart VS and computer... cleared my nuget feeds, configured again.. nothing, but then this fixed it! Thank you man so much!
M
MarkMiddlemist

Just to help out anyone who has landed on this page after updating VS2015 to update 2 and trying to manage packages on a website, receiving the "NuGet configuration file is invalid" error, this is a known and acknowledged issue:

https://connect.microsoft.com/VisualStudio/feedback/details/2698136/nuget-configuration-is-invalid-manage-nuget-packages-for-solution-disabled

I got mine working again by installing package manager 3.4.4 (beta) from http://dist.nuget.org/index.html

They do also state update 3 for Visual Studio will also contain a fix


Thanks a lot for this! :)
H
Hunter Tran

My guess is Nuget Package Manager is messing up with VSO. I create a new project, add packages to it just fine, check in TFS. Then I go home, "Get Latest Version", and Run, and fail because Nuget Package Manager doesn't restore my packages. Solution: on my home machine

open Nuget Package Manger, uninstall every packaged that have installed Open References folder, right click > Delete for all the packages you've installed Re-install them via Nuget Package Manager Check in


I tried adding/updating packages from a fresh project and experienced the same failed result. I've downgraded to VS2013 until the package manager is updated in VS2015
m
mike.bukosky

I was able to resolve this issue by reinstalling Nuget Package Manager via Tools -> Extensions and Updates


B
Belgi

I had this problem with Visual Studio 2017: It turns out that there are two class library projects - one for .Net and the other for C#. I created the one for .Net and when I tried to install a specific package (Nunit in my case) I got the error message.

Recreating the project as C# class library fixed the problem


r
raterus

In my case, This problem was caused by a mismatch in my Target framework setting under each project. When I created a new project, VS 2015 defaulted to 4.5.2, however all my nuget packages were built for 4.6.

For some reason, VS 2015 was not showing me these errors. I didn't see them until I created a new empty project and tried to add my nuget project there. This behavior may have been aggravated because I had renamed the project a few times during the initial setup.

I solved the problem by

changing the Target Framework on my projects to 4.6

closed VS 2015

deleted "packages", "obj" and "bin" folders

re-open the solution and try to add the nuget package again.


c
controlbox

I am using Visual Studio 2015 Update 3 and I managed to reproduce this error (despite Update 3 allegedly containing a fix).

As suggested above, a reliable fix is to do the following... 1) Exit Visual Studio, 2) Delete the packages folder, 3) Restart VS.

But... if you don't want to immediately exit VS for some reason, I was still able to add/remove packages from all projects by choosing the 'Manage NuGet Packages for Solution' option, rather than the individual Project with the issue.


Where is the packages folder everyone is talking about?
@ShrimpCrackers - in the same location as the solution (.sln) file
H
Hans Vonn

Repairing Visual Studio 2015 seems to have resolved this issue for me. See this issue for NuGet in GitHub.


C
Chidi-Nwaneto

Simply restarting Visual Studio works for me.. try restarting Visual Studio.


a
andynormancx

I had this problem, which seemed to be caused by something broken in the solution level packages folder. I deleted the contents of the folder and let nuget install all the packages again.

I could then install new packages again.


O
Orhan

Open the packages folder. Check if files with extension .deleteme exists, example Newtonsoft.Json.9.0.1.deleteme. Delete all the packages which have a .deleteme file manually. Delete the .deleteme files. Close and open the Nuget Explorer.


R
Rotem Varon

Change the "package source" in nuget to All

Details: None of the above helped in my case. My problem was that I restricted to only one private feed. Once I changed the "package source" to All, my problem was solved. I believe the crux of the matter is that my private pkg has a dependency on other pkgs from nuget.org.

I hope this can help someone


H
Heinz Kessler

In my case, nothing of the above helped. The root cause of the problem in my case was, that I uninstalled the package before and did not check in the change into source control (TFS in my case). After checking in the change (=the deletion of file in the packages folder), I could reinstall the package.


T
Timm

In my case, there was an empty packages.config file in the soultion directory, after deleting this, update succeeded