无法卸载/重新安装 NuGet 包 [英] Can't uninstall/reinstall NuGet package

查看:87
本文介绍了无法卸载/重新安装 NuGet 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Visual Studio Express 2012 设置了我的项目,添加了一些 C# 代码,并成功编译/部署到模拟器.在某个时候我决定用 JSON 做点什么,我发现我应该使用 Json.NET 框架,它是 作为 NuGet 包提供.我已经使用命令 Install-Package Newtonsoft.Json 成功添加了这个框架.

我两天前尝试安装 MSVC 提供的更新,但安装失败,使我无法再次打开我的项目.重新安装 MSVC 没有帮助,所以我最终将 Windows 恢复到以前的状态.我能够再次打开我的项目,我想重新安装 NuGet 包(不知道它安装在项目内部,不是 MSVC).它在安装时给了我错误,所以我尝试从包控制台卸载所有内容.

长话短说:

  • Nuget 软件包控制台在 Get-Package
  • 时显示未安装软件包"
  • 再次运行 Install-Package Newtonsoft.Json 给我错误<块引用>

    Newtonsoft.Json 5.0.6 无法安装.您尝试在引用WindowsPhone,Version=v8.0"的项目中安装此包,但该包不包含与此框架兼容的程序集

  • Manage NuGet"包对话框在已安装"下显示没有包,但是在在线包中,json包被列出并标记为已安装(所以我无法尝试安装它)

现在我完全迷失了.我不知道如何正确安装软件包,也不知道如何正确删除它.我的项目文件坏了吗?我该如何修复?

<小时>

现在它变得更加混乱.我刚刚更新了 NuGet 包管理器(虽然不是 MSVC),并尝试重新安装 Json.NET.

  • 在对话框中,它仍然没有显示在已安装"下
  • 在在线软件包列表中,它不再被标记为已安装,但单击安装"只是什么都不做
  • Get-Package 在控制台中显示已安装的包

    PM>获取包ID 版本说明/发行说明-- ------- -------------------------Newtonsoft.Json 5.0.6 Json.NET 是一种流行的 .NET 高性能 JSON 框架

  • 尝试使用Uninstall-Package Newtonsoft.Json"卸载时会出现找不到包‘Newtonsoft.Json’"

  • 在我的项目文件夹中,我可以在 packages 目录中看到一个Newtonsoft.Json.5.0.6"子文件夹

我应该从头开始创建一个新项目吗?:/

<小时>

packages.dgml 的内容:

解决方案

在您的解决方案或项目中,您将找到一个名为 packages.config 的文件.打开此文件,您将看到 NuGet 已安装的所有包.

文件看起来像这样:

只需删除包中的行并保存文件.

然后再次运行 NuGet 就可以安装了.

JSON.NET NuGet 包应该只使用 Windows Phone 8.0 项目.在 VS2012 NuGet 管理器中添加它会引入 JSON.NET 的 WP7 版本.(包Newtonsoft.Json.4.5.10libsl3-wpNewtonsoft.Json.dll)

JSON.NET 现在也可用作可移植类库,您可以从 WP8 使用它(可在 NuGet 或源形式中使用).

更新:

最新版本的 NuGet 已卸载.

VS 2013:

在解决方案中,右键单击引用"和管理 NuGet 包",您会在左上角找到已安装的包".选择软件包,即可使用卸载选项.

VS 2015:

在解决方案中,右键单击引用"和管理 NuGet 包",找到右上角的已安装"选项卡.将鼠标悬停在软件包上,X"将出现以卸载.

VS 2017:

在解决方案上,右键单击并管理解决方案的 NuGet 包",找到左上角的已安装"选项卡.单击软件包,右侧面板中将出现卸载"按钮.

VS 2019:

(与2017相同)在解决方案上,右键单击并管理解决方案的NuGet包",找到左上角的已安装"选项卡.单击软件包,右侧面板中将出现卸载"按钮.

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>

解决方案

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. (packagesNewtonsoft.Json.4.5.10libsl3-wpNewtonsoft.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.

这篇关于无法卸载/重新安装 NuGet 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆