简体   繁体   English

在Visual Studio 2013上启用NuGet包还原

[英]Enable NuGet Package Restore on Visual Studio 2013

I'm following this easy tutorial to start coding with the Google+ API in C#. 我正在按照这个简单的教程开始使用C#中的Google+ API进行编码。 However, I've been stuck for hours on Step 3, where the first substeps are: 但是,我在第3步遇到了几个小时,其中第一个子步骤是:

  1. In Visual Studio, click Project > Enable NuGet Package Restore > answer Yes in the dialog. 在Visual Studio中,单击“项目”>“启用NuGet包还原”>在对话框中回答“是”。
  2. Right-click on the gplus-quickstart-csharp project and select Manage NuGet Packages. 右键单击gplus-quickstart-csharp项目,然后选择Manage NuGet Packages。
  3. Click Restore on the Manage NuGet Packages window. 单击Manage NuGet Packages窗口中的Restore。 This will install the Google API Client libraries. 这将安装Google API客户端库。

When I click on Projet, there is no option "Enable NuGet Package Restore". 当我点击Projet时,没有选项“启用NuGet包恢复”。

There is a Manage Nuget Packages option, but no Restore button or option whatsoever. 一个管理的NuGet软件包选项,但没有还原按钮或选择任何责任。

The project doesn't build and gives me the error: 该项目没有构建并给我错误:

Error 1 This project references NuGet package(s) that are missing on this computer. 错误1此项目引用此计算机上缺少的NuGet包。 Enable NuGet Package Restore to download them. 启用NuGet Package Restore以下载它们。 For more information, see http://go.microsoft.com/fwlink/?LinkID=322105 . 有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105 The missing file is C:\\Users\\Documents\\google+\\gplus-quickstart-csharp\\.nuget\\NuGet.targets. 丢失的文件是C:\\ Users \\ Documents \\ google + \\ gplus-quickstart-csharp \\ .nuget \\ NuGet.targets。 C:\\Users\\Documents\\google+\\gplus-quickstart-csharp\\gplus-quickstart-csharp\\gplus-quickstart-csharp.csproj 201 5 gplus-quickstart-csharp C:\\ Users \\ Documents \\ google + \\ gplus-quickstart -csharp \\ gplus-quickstart-csharp \\ gplus-quickstart-csharp.csproj 201 5 gplus-quickstart-csharp

I went on the microsoft website and it only redirects to the NuGet documentation where I didn't find anything that works. 我去了微软网站,它只重定向到NuGet文档,在那里我找不到任何有用的东西。 I tried the following commands (described in the examples): 我尝试了以下命令(在示例中描述):

  • D:\\projects\\contoso> nuget.exe restore D:\\ projects \\ contoso> nuget.exe恢复
  • D:\\projects\\contoso> nuget.exe restore contoso.sln D:\\ projects \\ contoso> nuget.exe恢复contoso.sln
  • D:\\projects> nuget.exe restore contoso D:\\ projects> nuget.exe恢复contoso

but to no avail. 但无济于事。 And yes, NuGet is installed. 是的,NuGet已经安装完毕。 Any ideas? 有任何想法吗? Thanks! 谢谢!

To find the menu item: "enable nuget package restore" right-click in the solution explorer on the solution - not on the project. 要查找菜单项:在溶液中的解决方案资源管理器“使NuGet包还原”右击-不在项目。

You get a message: 你收到一条消息:

Do you want to configure this solution to download and restore missing NuGet packages during build? 您是否要配置此解决方案以在构建期间下载和还原丢失的NuGet包?

Wasn't that what you were looking for? 那不是你想要的吗?

You don't want to use the project based nuget package restore! 您不想使用基于项目的nuget包还原!

Make sure you have the latest Nuget version (Tools -> Extensions and Updates) 确保您拥有最新的Nuget版本(工具 - >扩展和更新)

When you go to build the project it should tell you it needs to download the nuget packages (or might just auto download them). 当你去构建项目时,它应该告诉你它需要下载nuget包(或者可能只是自动下载它们)。

Edit not sure whats with the downvotes: 编辑不确定与downvotes的什么:

http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

What the NuGet team is now recommending is both a lot cleaner and a lot simpler. NuGet团队现在推荐的是更清洁,更简单。 In short, you don't do anything special, and it just happens! 简而言之,你没有做任何特别的事情,它只是发生了! This is because NuGet now always restores packages before building in VS. 这是因为NuGet现在总是在构建VS之前恢复包。 So no changes whatsoever are needed on your files, which is beautiful! 因此,您的文件无需任何更改,这很美妙!

Since people are still having issues editing to include more information: 由于人们仍然在编辑问题以包含更多信息:

https://docs.nuget.org/consume/package-restore#common-issues-with-automatic-package-restore https://docs.nuget.org/consume/package-restore#common-issues-with-automatic-package-restore

Rename your .nuget folder then right-click on your solution. 重命名.nuget文件夹,然后右键单击您的解决方案。 Enable Nuget package restore should then be visible. 然后应该可以看到启用Nuget包还原。

I think you just want to know where to enable "Allow Nuget to download missing packages" 我想你只想知道在哪里启用“允许Nuget下载丢失的包”

In VS2013: Right Click on the project Select "Manage NuGet Packages for Solution" Then Click on "Settings" in new dialog click on "Manage NuGet Package Manager" root level Tick/Untick "Allow NuGet to download missing packages" 在VS2013中:右键单击项目选择“管理解决方案的NuGet包”然后在新对话框中单击“设置”单击“管理NuGet包管理器”根级别勾选/取消“允许NuGet下载丢失的包”

I had this problem and found a fix that may or may not work for you. 我遇到了这个问题并找到了一个可能适用于您的修复程序。 I had to edit the csproj files because they were pointing to wrong or non-existent packages folders. 我不得不编辑csproj文件,因为它们指向错误或不存在的包文件夹。

Look for the reference paths in your csproj file and be sure the packages folder path is correct: 在csproj文件中查找引用路径,并确保packages文件夹路径正确:

<HintPath>..\packages\path\to\file.dll</HintPath>

Maybe because of an unusual folder setup, that needs to be ..\\..\\packages . 也许是因为一个不寻常的文件夹设置,需要..\\..\\packages Also, towards the top, NuGet adds this line: 此外,在顶部,NuGet添加了这一行:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>

If you had to edit your HintPaths, you probably also need to edit this. 如果您必须编辑HintPaths,您可能还需要编辑它。 In my example you'd change the value to ..\\..\\ . 在我的示例中,您将值更改为..\\..\\ Finally, at the bottom, NuGet adds a target with the name EnsureNuGetPackageBuildImports . 最后,在底部,NuGet添加一个名为EnsureNuGetPackageBuildImports的目标。 You'll see a couple of attributes with the ..\\packages paths in them. 您将看到其中包含..\\packages路径的几个属性。 Again using my example, you'd have to change this to ..\\..\\packages . 再次使用我的示例,您必须将其更改为..\\..\\packages The base for all of these values is of course the folder containing the csproj file. 所有这些值的基础当然是包含csproj文件的文件夹。

It may be unusual for your folder paths to be set up in a non-default manner, but mine were, and this information would have been useful to me. 您的文件夹路径以非默认方式设置可能不常见,但我的,这些信息对我有用。

If you right-click on a project, and don't see the option to "Enable Nuget Package Restore", The reason why you do not SEE this option is because you do not have the latest version of nuget package installed in Visual Studio. 如果右键单击某个项目,但没有看到“启用Nuget包还原”选项,则您没有看到此选项的原因是您没有在Visual Studio中安装最新版本的nuget包。

The following steps will show you how to install the appropriate nuget package for the version of Visual Studio you are using. 以下步骤将向您展示如何为您正在使用的Visual Studio版本安装相应的nuget包。 Click on Tools->Extensions and Update. 单击工具 - >扩展和更新。 Extensions and Update Dialog will appear. 将出现“扩展和更新”对话框。 Click on online in the left hand column of the dialog. 单击对话框左侧栏中的在线。 You should see as first package in list "Nuget Package Manager for Visual Studio 2013. Click on the 'download' button to install. You may then have to restart Visual Studio. 您应该看到列表中的第一个包“Visual Studio 2013的Nuget包管理器。单击'下载'按钮进行安装。然后您可能必须重新启动Visual Studio。

Now re-open your solution and right-click on the solution name. 现在重新打开解决方案并右键单击解决方案名称。 You should now see a dialog popup asking you if you want to restore packages for this solution. 您现在应该看到一个对话框弹出窗口,询问您是否要还原此解决方案的包。 If you select 'yes' then anytime you build your solution nuget will attempt to download and of the corresponding packages your solution is using. 如果您选择“是”,那么无论何时构建解决方案,nuget都会尝试下载您的解决方案所使用的相应软件包。

In my situation, I just created a new solution and the solution file hadn't been saved yet. 在我的情况下,我刚刚创建了一个新的解决方案,解决方案文件尚未保存。 Make sure the solution is saved before "Enabling Nuget Package Restore" 确保在“启用Nuget包还原”之前保存解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 中启用 NuGet Package 还原? - How do I enable NuGet Package Restore in Visual Studio? 如何解决 Visual Studio 中的“NuGet package 还原失败”? - How to resolve "NuGet package restore failed" in Visual Studio? Nuget程序包可能引起的Visual Studio 2013错误? - Possible Visual Studio 2013 Bug Caused by Nuget Package? 在 Visual Studio 中执行“还原 Nuget 包”时未复制 Nuget 包文件 - Nuget package files not copied when doing a "Restore Nuget Package" in Visual Studio Visual Studio编译错误-计算机中缺少nuget软件包,但是nuget restore表示已安装所有软件包? - Visual Studio compile error - nuget package missing from computer, but nuget restore says all packages installed? Nuget 包未在 Visual Studio 中更新 - Nuget package not updating in Visual Studio 如何恢复 Visual Studio nuget 包? - How to restore visual studio nuget packages? Visual Studio NuGet无法还原包 - Visual Studio NuGet Cannot Restore Packages 我已经使用NuGet在Visual Studio 2013中安装了SQLite,但该包从未出现在“引用”中 - I've installed SQLite in Visual Studio 2013 using NuGet but the package never appears in References Visual Studio 2013套件问题 - Visual Studio 2013 package issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM