Can't uninstall/reinstall NuGet package
Asked Answered
G

6

45

I've set up my project with Visual Studio Express 2012, added some C# code, and successfully compiled/deployed to emulator. At some point I decided I want to do something with JSON, and I found that I should use the Json.NET framework, which is available as a NuGet package. I have added this framework successfully using the command Install-Package Newtonsoft.Json.

I tried to install an update which MSVC offered two days ago, and the installation failed, leaving me unable to open my project again. Reinstalling MSVC didn't help, so I ended up restoring Windows to a previous state. I was able to open my project again, and I wanted to reinstall the NuGet package (not knowing it is installed inside the project, not MSVC). It gave me errors upon installing, so I tried to uninstall everything from package console.

Long story short:

  • Nuget package console says "no packages installed" when Get-Package
  • Running Install-Package Newtonsoft.Json again gives me the error

    Newtonsoft.Json 5.0.6 could not be installed. You try to install this package in a project referencing "WindowsPhone,Version=v8.0", the package however does not contain assemblies compatible with this framework

  • The "Manage NuGet" packages dialog shows no packages under "installed", however in the online package, the json package is listed and marked as installed (so I cannot try to install it)

Now I'm completely lost. I don't know how to install the package properly, nor how to remove it properly. Is my project file broken? How can I repair it?


[edit] Now it gets even more confusing. I've just updated the NuGet package manager (not MSVC though), and tried to reinstall Json.NET.

  • In the dialog it's still not shown under "installed"
  • In the online packages list it is no more marked as installed, but clicking "Install" just does nothing
  • Get-Package in the console shows the package as installed

    PM> Get-Package
    
    Id                             Version              Description/Release Notes                                                                                                                                                                                            
    --                             -------              -------------------------                                                                                                                                                                                            
    Newtonsoft.Json                5.0.6                Json.NET is a popular high-performance JSON framework for .NET
    
  • Trying to uninstall with `Uninstall-Package Newtonsoft.Json" gives "The Package 'Newtonsoft.Json' could not be found"

  • In my project folder I can see a "Newtonsoft.Json.5.0.6" subfolder in the packages directory

Should I just start over from scratch and create a new project? :/


Contents of packages.dgml:

<?xml version="1.0" encoding="utf-8"?>
<DirectedGraph GraphDirection="LeftToRight" xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes />
  <Links />
  <Categories>
    <Category Id="Projekt" />
    <Category Id="Paket" />
  </Categories>
  <Styles>
    <Style TargetType="Node" GroupLabel="Projekt" ValueLabel="True">
      <Condition Expression="HasCategory('Projekt')" />
      <Setter Property="Background" Value="Blue" />
    </Style>
  </Styles>
</DirectedGraph>
Greaser answered 5/9, 2013 at 7:32 Comment(4)
You can try to open the packages.config and remove the Newtonsoft.Json entry - that should solve your third bullet point. Then maybe you will be able to re-install it from the NuGet Package Manager window. Your second bullet point makes me kind of doubt it though...Chessy
So, were you using the Package Manager before? and now you installed NuGet? You could try going into the package manager and uninstalling from there. (Tools -> Library Package Manager)Schwab
As stated above, I can't uninstall from there, since its not listed as installed. Funny: I've just created a plain new project, added the package via NuGet, and now I also have a packages.config file in my project folder, but no Packages.dgml. I think I'm just going to start over then. Still thanks for the help.Greaser
I updated my answer to reflect the fact that there is now an uninstall in NuGet.Schwab
S
64

In your Solution or Project you will find a file called packages.config. Open this file and you will see all the packages that NuGet has installed.

The file will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Json" version="2.0.3" targetFramework="net45" />
</packages>

Simply delete the line of your package and save the file.

<?xml version="1.0" encoding="utf-8"?>
<packages>
</packages>

Then run NuGet again and it should install.

The JSON.NET NuGet package should just work with a Windows Phone 8.0 project. Adding it in VS2012 NuGet manager pulls in the WP7 version of JSON.NET. (packages\Newtonsoft.Json.4.5.10\lib\sl3-wp\Newtonsoft.Json.dll)

JSON.NET is now also available as a Portable Class Library which you can consume from WP8 (available in NuGet or in source form).

UPDATE:

The latest version of NuGet has an uninstall.

VS 2013:

In the solution, right click on References and Manage NuGet packages, you will find "Installed Packages" in the upper left hand corner. Select the package and an uninstall option will be available.

VS 2015:

In the solution, right click on References and Manage NuGet packages, find the "Installed" tab in the upper right. Hover over the package and the "X" will appear to uninstall.

VS 2017:

On the solution, right click and "Manage NuGet packages for solution", find the "Installed" tab in the upper left. Click on the package and in the right hand panel will be an "Uninstall" button.

VS 2019:

(Identical to 2017) On the solution, right click and "Manage NuGet packages for solution", find the "Installed" tab in the upper left. Click on the package and in the right hand panel will be an "Uninstall" button.

VS 2022:

(Identical to 2017 & 2019) On the solution, right click and "Manage NuGet packages for solution", find the "Installed" tab in the upper left. Click on the package and in the right hand panel will be an "Uninstall" button.
Schwab answered 5/9, 2013 at 7:38 Comment(7)
I can't find a file called packages.config. Explorer does not find this file in my project directory. Do you mean Packages.dgml in the root of my project? It does not contain the XML you mentioned.Greaser
That has to be the file. DGML is usually viewed graphically, but the underlying info is XML. Are you able to get to the XML view?Schwab
Nope, thats not the file.Schwab
In VS 2019, when I click the uninstall button, it still shows an error that it can't find the package. Why does Visual Studio need to install something to uninstall it? EDIT: Erasing the entry from packages.config worked perfectly.Jeffryjeffy
@AaronFranke glad to hear it. Its been helpful to leave all the versions on this answer for reasons JUST like that :)Schwab
What do you mean by "run NuGet" again?Showily
@mijkolsmith, that is ancient by this point. In VS 2012 when this answer was written, nuget was run on the command line. Follow the directions of your version in the update section of the answer and you should be able to fix any problems.Schwab
N
27

I had the same problem. I wasn't able to re-install my package even after all the package.config modifications. Here what work for me.

In your solution folder there should be a "packages" directory. Open this directory and delete the directory associated with your package.

Done.

Norbertonorbie answered 20/2, 2014 at 16:26 Comment(0)
L
8

Just sat four hours on my new Windows 10 machine and couldn't figure out why no references worked in Visual Studio 2015 and why I could not restore NuGet packages. For some reason TFS added two packages folders:

Locations:

C:\Users\YourUser\Documents\Visual Studio 2015\Projects\YourProject\packages

C:\Users\YourUser\.nuget\packages

When both of the package folders were removed I could restore NuGet packages and everything worked again.

Levee answered 19/10, 2015 at 12:10 Comment(0)
A
1

It is indeed a bit confusing, but there are different options available if you right-click the solution and choose manage nuget packages. You should be able to uninstall from there.

You should check the answer here: Windows Phone 8 JSON for more information on Json.net and WP8.

Alessandro answered 5/9, 2013 at 7:39 Comment(0)
I
0

I tried this solution and its works

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>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=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Impressionism answered 9/2, 2017 at 11:25 Comment(0)
V
0

I had a similar problem in VS2017 (fresh install). I was working with an older project trying to install a relatively new package. When I would install the package from the GUI, it flashed for a second, then did nothing.

The problem was that my project had a lower .NET target than the package. (My solution was targeting 4.5, and the package targeted 4.6). Changing the .NET target to a new enough version in my project configuration and rebuilding fixed the issue.

This issue can be seen by running the following commands: (Names changed)

PM> Install-Package Package.NET

Attempting to gather dependency information for package 'Package.NET.1.0.0' with respect to project 'MyProject', targeting '.NETFramework,Version=v4.5'
Gathering dependency information took 0.19 ms
Attempting to resolve dependencies for package 'Package.NET.1.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Package.NET.1.0.0'
Resolved actions to install package 'Package.NET.1.0.0'
Retrieving package 'Package.NET.1.0.0' from 'nuget.org'.
Install failed. Rolling back...
Package 'Package.NET.1.0.0' does not exist in project 'MyProject'
Package 'Package.NET.1.0.0' does not exist in folder 'C:\Code\MyProject\packages'
Executing nuget actions took 13.92 ms
Install-Package : Could not install package 'Package.NET.1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', 
but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Package.NET
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Ventriculus answered 14/7, 2017 at 5:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.