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
.
我已经用Visual Studio Express 2012设置了我的项目,添加了一些c#代码,并成功地编译/部署到仿真器。在某个时候,我决定用JSON做点什么,我发现应该使用JSON。NET框架,可以作为NuGet包使用。我已经使用命令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.
我试图安装MSVC两天前提供的更新,但是安装失败了,导致我无法再次打开我的项目。重新安装MSVC没有帮助,所以我最终将Windows恢复到以前的状态。我可以再次打开我的项目,我想重新安装NuGet包(不知道它是在项目内部安装的,而不是MSVC)。在安装时它给了我错误,所以我尝试从包控制台卸载一切。
Long story short:
长话短说:
- Nuget package console says "no packages installed" when
Get-Package
- Nuget包控制台在收到包时显示“没有安装包”
- Running
Install-Package Newtonsoft.Json
again gives me the errorNewtonsoft.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
Newtonsoft。无法安装Json 5.0.6。您尝试在引用“WindowsPhone,Version=v8.0”的项目中安装此包,但是该包不包含与此框架兼容的程序集
- 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)
- “Manage NuGet”包对话框显示“installed”下没有包,但是在联机包中,json包被列出并标记为installed(因此我无法尝试安装它)
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.
(编辑)现在更让人困惑了。我刚刚更新了NuGet包管理器(不是MSVC),并尝试重新安装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
- 在在线软件包列表中,它不再被标记为已安装,但是点击“Install”就什么都不做了
-
Get-Package
in the console shows the package as installed控制台中的Get-Package显示已安装的包
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"
尝试卸载“uninstall - package Newtonsoft”。Json给了“软件包”Newtonsoft。无法找到Json "
- In my project folder I can see a "Newtonsoft.Json.5.0.6" subfolder in the
packages
directory - 在我的项目文件夹中,我可以在package目录中看到一个“Newtonsoft.Json.5.0.6”子文件夹
Should I just start over from scratch and create a new project? :/
我是否应该从头开始,创建一个新的项目?:/
Contents of packages.dgml:
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>
6 个解决方案
#1
39
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.
在您的解决方案或项目中,您将找到一个名为packag .config的文件。打开这个文件,您将看到NuGet安装的所有包。
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.
然后再运行NuGet,它就应该安装了。
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 NuGet包应该只适用于Windows Phone 8.0项目。在VS2012的NuGet管理器中添加它,将引入JSON.NET的WP7版本。(包\ 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).
JSON。NET现在也可以作为一个可移植类库使用,您可以从WP8(在NuGet或源代码形式中可用)使用。
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 2013:在解决方案中,右键单击引用并管理NuGet包,您将在左上角找到“已安装包”。选择包,卸载选项将可用。
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 2015:在解决方案中,右键单击引用并管理NuGet包,找到右上角的“install”选项卡。将鼠标悬停在包上,“X”将显示为卸载。
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 2017:在解决方案上,右击并“管理解决方案的NuGet包”,找到左上角的“Installed”选项卡。点击软件包,在右手面板将是一个“卸载”按钮。
#2
23
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.
完成了。
#3
6
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:
我只花了四个小时在我的新Windows 10机器上,不明白为什么在Visual Studio 2015中没有引用,为什么我不能恢复NuGet包。由于某些原因,TFS增加了两个包文件夹:
Locations:
地点:
C:\Users\YourUser\Documents\Visual Studio 2015\Projects\YourProject\packages
C:\Users\YourUser\Documents\Visual Studio 2015 \ \项目志愿者项目\包
C:\Users\YourUser\.nuget\packages
C:\Users\YourUser\.nuget\packages
When both of the package folders were removed I could restore NuGet packages and everything worked again.
当两个包文件夹被删除时,我可以恢复NuGet包,然后一切都恢复正常。
#4
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.
这确实有点令人困惑,但如果您右键单击解决方案并选择manage nuget包,则可以使用不同的选项。您应该能够从那里卸载。
You should check the answer here: Windows Phone 8 JSON for more information on Json.net and WP8.
您应该在这里检查答案:Windows Phone 8 JSON获取更多关于Json.net和WP8的信息。
#5
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>
#6
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.
我在VS2017(新安装)遇到了类似的问题。我正在与一个较老的项目合作,试图安装一个相对较新的包。当我从GUI安装包时,它闪了一下,然后什么也没做。
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.
问题是我的项目的。net目标比包低。(我的解决方案是针对4.5,而包的目标是4.6)。在我的项目配置中将。net目标更改为一个新的足够的版本并重新构建解决了这个问题。
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
#1
39
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.
在您的解决方案或项目中,您将找到一个名为packag .config的文件。打开这个文件,您将看到NuGet安装的所有包。
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.
然后再运行NuGet,它就应该安装了。
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 NuGet包应该只适用于Windows Phone 8.0项目。在VS2012的NuGet管理器中添加它,将引入JSON.NET的WP7版本。(包\ 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).
JSON。NET现在也可以作为一个可移植类库使用,您可以从WP8(在NuGet或源代码形式中可用)使用。
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 2013:在解决方案中,右键单击引用并管理NuGet包,您将在左上角找到“已安装包”。选择包,卸载选项将可用。
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 2015:在解决方案中,右键单击引用并管理NuGet包,找到右上角的“install”选项卡。将鼠标悬停在包上,“X”将显示为卸载。
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 2017:在解决方案上,右击并“管理解决方案的NuGet包”,找到左上角的“Installed”选项卡。点击软件包,在右手面板将是一个“卸载”按钮。
#2
23
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.
完成了。
#3
6
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:
我只花了四个小时在我的新Windows 10机器上,不明白为什么在Visual Studio 2015中没有引用,为什么我不能恢复NuGet包。由于某些原因,TFS增加了两个包文件夹:
Locations:
地点:
C:\Users\YourUser\Documents\Visual Studio 2015\Projects\YourProject\packages
C:\Users\YourUser\Documents\Visual Studio 2015 \ \项目志愿者项目\包
C:\Users\YourUser\.nuget\packages
C:\Users\YourUser\.nuget\packages
When both of the package folders were removed I could restore NuGet packages and everything worked again.
当两个包文件夹被删除时,我可以恢复NuGet包,然后一切都恢复正常。
#4
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.
这确实有点令人困惑,但如果您右键单击解决方案并选择manage nuget包,则可以使用不同的选项。您应该能够从那里卸载。
You should check the answer here: Windows Phone 8 JSON for more information on Json.net and WP8.
您应该在这里检查答案:Windows Phone 8 JSON获取更多关于Json.net和WP8的信息。
#5
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>
#6
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.
我在VS2017(新安装)遇到了类似的问题。我正在与一个较老的项目合作,试图安装一个相对较新的包。当我从GUI安装包时,它闪了一下,然后什么也没做。
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.
问题是我的项目的。net目标比包低。(我的解决方案是针对4.5,而包的目标是4.6)。在我的项目配置中将。net目标更改为一个新的足够的版本并重新构建解决了这个问题。
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