如何让NuGet安装/更新package .config中的所有包?

时间:2023-01-12 19:57:13

I have a solution with multiple projects in it. Most of the third party references are missing, yet there are packages.config file for each project. How do I get NuGet to install/update all the packages needed? Does this need to be done via command line for each project?

我有一个包含多个项目的解决方案。大多数第三方引用都没有,但是有包。每个项目的配置文件。如何让NuGet安装/更新所需的所有包?这是否需要通过命令行为每个项目完成?

15 个解决方案

#1


663  

You can use nuget.exe to restore your packages or with NuGet 2.7, or above, installed you can simply compile your solution in Visual Studio, which will also restore the missing packages.

您可以使用nuget。exe可以恢复您的包或使用NuGet 2.7或以上安装,您只需在Visual Studio中编译解决方案,该解决方案也将恢复丢失的包。

For NuGet.exe you can run the following command for each project.

NuGet。exe可以为每个项目运行以下命令。

nuget install packages.config

Or with NuGet 2.7 you can restore all packages in the solution using the command line.

或者使用NuGet 2.7,您可以使用命令行恢复解决方案中的所有包。

nuget restore YourSolution.sln

Both of these will pull down the packages. Your project files will not be modified however when running this command so the project should already have a reference to the NuGet packages. If this is not the case then you can use Visual Studio to install the packages.

这两个都将拉下包。然而,在运行此命令时,您的项目文件不会被修改,因此项目应该已经有了对NuGet包的引用。如果不是这样,那么您可以使用Visual Studio来安装包。

With NuGet 2.7, and above, Visual Studio will automatically restore missing NuGet packages when you build your solution so there is no need to use NuGet.exe.

使用NuGet 2.7和以上版本,在构建解决方案时,Visual Studio将自动恢复丢失的NuGet包,因此不需要使用NuGet.exe。

To update all the packages in your solution, first restore them, and then you can either use NuGet.exe to update the packages or from within Visual Studio you can update the packages from the Package Manager Console window, or finally you can use the Manage Packages dialog.

要更新解决方案中的所有包,首先要恢复它们,然后可以使用NuGet。exe更新软件包或从Visual Studio中,您可以从包管理控制台窗口更新包,或者最后您可以使用Manage packages对话框。

From the command line you can update packages in the solution to the latest version available from nuget.org.

从命令行可以将解决方案中的包更新到nuget.org上的最新版本。

nuget update YourSolution.sln

Note that this will not run any PowerShell scripts in any NuGet packages.

注意,这不会在任何NuGet包中运行任何PowerShell脚本。

From within Visual Studio you can use the Package Manager Console to also update the packages. This has the benefit that any PowerShell scripts will be run as part of the update where as using NuGet.exe will not run them. The following command will update all packages in every project to the latest version available from nuget.org.

在Visual Studio中,您可以使用包管理器控制台来更新包。这样做的好处是,任何PowerShell脚本都将在使用NuGet时作为更新的一部分运行。exe不会运行它们。下面的命令将把每个项目中的所有包更新到nuget.org的最新版本。

Update-Package

You can also restrict this down to one project.

您还可以将其限制为一个项目。

Update-Package -Project YourProjectName

If you want to reinstall the packages to the same versions as were previously installed then you can use the -reinstall argument with Update-Package command.

如果希望将包重新安装到以前安装的相同版本,那么可以使用-reinstall参数和Update-Package命令。

Update-Package -reinstall

You can also restrict this down to one project.

您还可以将其限制为一个项目。

Update-Package -reinstall -Project YourProjectName

The -reinstall option will first uninstall and then install the package back again into a project.

“重新安装”选项将首先卸载,然后将包重新安装到项目中。

Or, you can update the packages using the Manage Packages dialog.

或者,您可以使用Manage packages对话框更新包。

Updates:

更新:

  • 2013/07/10 - Updated with information about nuget restore in NuGet 2.7
  • 2013/07/10——在nuget 2.7中更新有关nuget恢复的信息
  • 2014/07/06 - Updated with information about automatic package restore in Visual Studio and brought the answer up to date with other changes to NuGet.
  • 2014/07/06——在Visual Studio中更新了关于自动恢复包的信息,并在NuGet中更新了答案。
  • 2014/11/21 - Updated with information about -reinstall
  • 2014/11/21 -更新-重新安装信息

#2


434  

Reinstall all packages in ALL PROJECTS of the current solution:

在当前解决方案的所有项目中重新安装所有包:

Update-Package -Reinstall

Reinstall all packages in SPECIFIC PROJECT of the current solution (Thanks to unarity and ashes999):

在当前解决方案的特定项目中重新安装所有包(感谢unarity和ashes999):

Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall

#3


164  

There is another, newer and quicker way to do this from within Visual Studio. Check out this post by David Ebbo, and reference the comments section if you run into trouble. Basically, you do the following in Package Manager prompt:

在Visual Studio中还有另一种更新、快捷的方法来实现这一点。查看David Ebbo的这篇文章,如果遇到麻烦,请参考评论部分。基本上,您在Package Manager提示符中执行以下操作:

PM> Install-Package NuGetPowerTools
PM> Enable-PackageRestore

Afterwards, when you build your solution the packages will be automatically installed if they're missing.

之后,当您构建您的解决方案时,如果包丢失,将自动安装它们。

Update:

更新:

This functionality is built into Nuget 1.6 with visual studio integration so you don't even need to install NuGetPowerTools or type commands. All you have to do is

这个功能被内置到Nuget 1.6中,并带有visual studio集成,因此您甚至不需要安装NuGetPowerTools或type命令。你所要做的就是

Right click on the Solution node in Solution Explorer and select Enable NuGet Package Restore.

右键单击解决方案资源管理器中的解决方案节点,并选择Enable NuGet包恢复。

Read this article for more details.

更多细节请阅读本文。

#4


18  

Here's another solution if you are using website projects, or don't want to enable NuGet Package restore.

如果您正在使用网站项目,或者不想启用NuGet包恢复,这里有另一个解决方案。

You can use the package manager console to enumerate all the packages in the package.config file and re-install them.

您可以使用包管理器控制台枚举包中的所有包。配置文件并重新安装它们。

# read the packages.config file into an XML object
[xml]$packages = gc packages.config

# install each package 
$packages.packages.package | % { Install-Package -id $($_.id) -Version $($_.version) }

#5


14  

Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall

This is best and easiest example I found. It will reinstall all nugets that are listed in packages.config and it will preserve current versions. Replace YourProjectNameGoesHere with the project name.

这是我找到的最好和最简单的例子。它将重新安装包中列出的所有nuget。配置并保存当前版本。将您的projectnamegoeshere替换为项目名。

#6


10  

With the latest NuGet 2.5 release there is now an "Update All" button in the packages manager: http://docs.nuget.org/docs/release-notes/nuget-2.5#Update_All_button_to_allow_updating_all_packages_at_once

在最新的NuGet 2.5版本中,现在包管理器中有一个“Update All”按钮:http://docs.nuget.org/docs/release-notes/nuget-2.5# update_all_button_allow_updating_allages_at_at_once

#7


5  

I'm using visual studio 2015 and the solutions given above didn't work for me, so i did the following:

我使用的是visual studio 2015,上面给出的解决方案对我不起作用,所以我做了如下的事情:

Delete the packages folder from my solution and also bin and obj folders from every project in the solution and give it a rebuild.

从我的解决方案中删除package文件夹,并从解决方案中的每个项目中删除bin和obj文件夹,并对其进行重新构建。

Maybe you will have the next error:

也许你会有下一个错误:

unable to locate nuget.exe

无法找到nuget.exe

To solve this: Change this line in your NuGet.targets file and setting it to true:

要解决这个问题:在你的NuGet中改变这条线。目标文件并将其设置为true:

<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>

Reference:https://*.com/a/30918648 and https://*.com/a/20502049

参考:https://*.com/a/30918648和https://*.com/a/20502049

#8


3  

I believe the first thing you need to do is enable the package restore feature. See also here. This is done at the solution (not project) level.

我相信您需要做的第一件事是启用包恢复功能。参见这里。这是在解决方案(而不是项目)级别上完成的。

But that won't get you all the way -- I ran into a similar issue after having enabled the restore feature. (VS2013, NuGet 2.8.)

但这并不能完全解决问题——我在启用恢复功能后遇到了类似的问题。(VS2013 NuGet 2.8。)

It turned out I had (unintentionally) committed the packages to source control when I committed the project -- but Visual Studio (and the source control plugin) had helpfully ignored the binaries when performing the check-in.

结果证明,当我提交项目时(无意中)我将包提交给了源代码控制——但是Visual Studio(和源代码控制插件)在执行签入时有效地忽略了二进制文件。

The problem arose when I created a release branch. My local copy of the dev/main/trunk branch had the binaries, because that's where I had originally installed/downloaded the packages.
However, in the new release branch,

当我创建发布分支时出现了问题。我的dev/main/主干分支的本地副本有二进制文件,因为这是我最初安装/下载包的地方。然而,在新的发布分支中,

  • the package folders and .nupkg files were all there -- so NuGet didn't think there was anything to restore;
  • 包文件夹和.nupkg文件都在那里——所以NuGet不认为有什么要恢复;
  • but at the same time, none of the DLLs were present -- i.e. the third-party references were missing -- so I couldn't build.
  • 但与此同时,没有dll存在——也就是说,没有第三方引用——所以我无法构建。

I deleted all the package folders in $(SolutionDir)/packages (under the release branch) and then ran a full rebuild, and this time the build succeeded.
... and then of course I went back and removed the package folders from source control (in the trunk and release branch). I'm not clear (yet) on whether the repositories.config file should be removed as well.

我删除了$(SolutionDir)/packages(发布分支下)中的所有包文件夹,然后进行了完整的重新构建,这次构建成功了……然后,当然,我返回并从源代码控制(在主干和发布分支中)删除了包文件夹。我还不清楚是否有存储库。配置文件也应该被删除。

Many of the components installed for you by the project templates -- at least for web projects -- are NuGet packages. That is, this issue is not limited to packages you've added.
So enable package restore immediately after creating the project/solution, and before you perform an initial check-in, clear the packages folder (and make sure you commit the .nuget folder to source control).

项目模板为您安装的许多组件(至少对于web项目)是NuGet包。也就是说,这个问题不仅限于您添加的包。因此,在创建项目/解决方案之后立即启用包恢复,在执行初始签入之前,清除包文件夹(并确保将.nuget文件夹提交到源代码控制中)。

Disclaimer: I saw another answer here on SO which indicated that clearing the packages folder was part of the resolution. That put me on the right track, so I'd like to give the author credit, but I can no longer locate that question/answer. I'll post an edit if I stumble across it.

免责声明:我在这里看到了另一个答案,表明清理包文件夹是解决方案的一部分。这让我走上了正确的道路,所以我想给作者加分,但我再也找不到那个问题/答案了。如果我偶然发现它,我会发布一个编辑。

I'd also note that Update-Package -reinstall will modify the .sln and .csproj/.vbproj files. At least that's what it did in my case. Which IMHO makes this option much less attractive.

我还注意到,Update-Package -reinstall将修改.sln和.csproj/。vbproj文件。至少在我的例子里是这样的。这使得IMHO这个选项的吸引力大大降低。

#9


3  

After 3 hours of searching and investigation.

经过3小时的搜寻和调查。

I had problems with it because we have two members in team (using GitHub source control), because we didn't restrict files for packages for sending to remote repository, one of team members was send packages to server and i have pull that changes to my local.

我遇到了一些问题,因为我们团队中有两个成员(使用GitHub源代码控制),因为我们没有限制将包发送到远程存储库的文件,其中一个团队成员将包发送到服务器,我已经将这些更改拖到本地。

After that i had same problem as PO, also i wasn't be able to publish my API project to server.

在此之后,我遇到了与PO相同的问题,我也无法将我的API项目发布到服务器上。

At the and I have just used

我刚刚用过

Update-Package -Reinstall - run this command on Package Manager Console

更新包-重新安装-在包管理器控制台上运行这个命令。

This command will reinstall all your packages that you have used in your solution. (For every project)

此命令将重新安装您在解决方案中使用的所有包。(每个项目)

Reinstall all packages in ALL PROJECTS of the current solution:

在当前解决方案的所有项目中重新安装所有包:

Update-Package -ProjectName 'NameOfProject' -Reinstall - run this command on Package Manager Console

Update-Package - projectname 'NameOfProject' - reinstall -在Package Manager控制台运行这个命令

This command will reinstall all your packages that are in relation with project that you specified after "-ProjectName". And i think that this is better because i had wait for half a hour to reinstall all packages in solution.

此命令将重新安装与您在“-ProjectName”之后指定的项目相关的所有包。我认为这样更好,因为我已经等了半个小时来重新安装解决方案中的所有包。

For this many thanks to Rodolpho Brock.

感谢罗道夫·布洛克。

Also, I would recommend you that when you pull changes from remote server, to press "Restore packages" button that will be shown by Visual studio.

另外,我建议您在从远程服务器提取更改时,按一下Visual studio将显示的“恢复包”按钮。

#10


2  

For those arriving here due to the build server falling foul of this, you can create an MSBuild target running the exec command to run the nuget restore command, as below (in this case nuget.exe is in the .nuget folder, rather than on the path), which can then be run in a TeamCity build step immediately prior to building the solution

对于由于构建服务器出现问题而到达这里的用户,可以创建一个MSBuild目标,运行exec命令来运行nuget恢复命令,如下所示(在本例中为nuget)。exe位于.nuget文件夹中,而不是路径中),然后可以在构建解决方案之前立即在TeamCity构建步骤中运行

<Target Name="BeforeBuild">
  <Exec Command="..\.nuget\nuget restore ..\MySolution.sln"/>
</Target>

#11


2  

If you Nuget 2.8 install, check the checkbox

如果您使用Nuget 2.8安装,请选中复选框

Tools >> Nuget Manager >> Package Manager Settings >> Automatically check for missing packages during build

in Visual Studio. If it is checked, then simply rebuild the project will restore all your reference libraries.

在Visual Studio。如果选中它,那么只需重新构建项目就可以恢复所有的参考库。

#12


1  

now Nuget Package Manager Console in Visual Studio 2012 gives you a "Restore" button automatically as soon it find any package not installed but in there in package.config. Awesome Feature!

现在,Visual Studio 2012中的Nuget包管理器控制台会自动为您提供一个“恢复”按钮,当它发现没有安装任何包时,它会在Package .config中。很棒的功能!

#13


1  

At VS2012 V11, if I use "-Reinstall" at the end of the line it doesn't work.

在VS2012 V11中,如果我在行尾使用“-Reinstall”,它就不能工作。

So I simply used:

所以我仅仅使用:

Update-Package -ProjectName 'NAME_OF_THE_PROJECT'

#14


1  

I know this is an old post, but thought this could be useful. If you have a need to ignore specific packages during the update process (like any packages that update JavaScript references), use the following PowerShell script (make sure your package source is set to "All" in Package Manager Console):

我知道这是一个旧帖子,但认为这可能有用。如果在更新过程中需要忽略特定的包(如任何更新JavaScript引用的包),请使用以下PowerShell脚本(请确保在包管理器控制台将包源设置为“All”):

EDIT 2014-09-25 10:55 AM EST - Fixed a bug in the script

编辑2014-09-25上午10:55 EST -修复了脚本中的一个错误

$packagePath = "packages.config"
$projectName = "MyProjectName"

$packagesToIgnore = @(
    "bootstrap",
    "jQuery",
    "jquery-globalize",
    "jquery.mobile",
    "jQuery.jqGrid",
    "jQuery.UI.Combined",
    "jQuery.Validation",
    "Microsoft.jQuery.Unobtrusive.Validation",
    "Modernizr",
    "Moment.js"
)

[xml]$packageFile = gc $packagePath
$packagesToProcess = $packageFile.packages.package | Where-Object {$packagesToIgnore -notcontains $_.id}

$packagesToProcess | % { Update-Package -reinstall -projectname $projectName -id $($_.id) }

#15


0  

In Visual Studio 2017 - When you compile using IDE - It will download all the missing nuget packages and save in the folder "packages".

在Visual Studio 2017——当您使用IDE编译时——它将下载所有丢失的nuget包并保存到“packages”文件夹中。

But on the build machine compilation was done using msbuild.exe. In that case, I downloaded nuget.exe.

但是在构建机器上,编译是使用msbuild.exe完成的。在这种情况下,我下载了nuget.exe。

During each build process before executing msbuild.exe. It will execute -> nuget.exe restore NAME_OF_SLN_File (if there is only one .SLN file then you can ignore that parameter).

在执行msbuild.exe之前的每个构建过程中。它将执行-> nuget。exe还原NAME_OF_SLN_File(如果只有一个. sln文件,则可以忽略该参数)。

#1


663  

You can use nuget.exe to restore your packages or with NuGet 2.7, or above, installed you can simply compile your solution in Visual Studio, which will also restore the missing packages.

您可以使用nuget。exe可以恢复您的包或使用NuGet 2.7或以上安装,您只需在Visual Studio中编译解决方案,该解决方案也将恢复丢失的包。

For NuGet.exe you can run the following command for each project.

NuGet。exe可以为每个项目运行以下命令。

nuget install packages.config

Or with NuGet 2.7 you can restore all packages in the solution using the command line.

或者使用NuGet 2.7,您可以使用命令行恢复解决方案中的所有包。

nuget restore YourSolution.sln

Both of these will pull down the packages. Your project files will not be modified however when running this command so the project should already have a reference to the NuGet packages. If this is not the case then you can use Visual Studio to install the packages.

这两个都将拉下包。然而,在运行此命令时,您的项目文件不会被修改,因此项目应该已经有了对NuGet包的引用。如果不是这样,那么您可以使用Visual Studio来安装包。

With NuGet 2.7, and above, Visual Studio will automatically restore missing NuGet packages when you build your solution so there is no need to use NuGet.exe.

使用NuGet 2.7和以上版本,在构建解决方案时,Visual Studio将自动恢复丢失的NuGet包,因此不需要使用NuGet.exe。

To update all the packages in your solution, first restore them, and then you can either use NuGet.exe to update the packages or from within Visual Studio you can update the packages from the Package Manager Console window, or finally you can use the Manage Packages dialog.

要更新解决方案中的所有包,首先要恢复它们,然后可以使用NuGet。exe更新软件包或从Visual Studio中,您可以从包管理控制台窗口更新包,或者最后您可以使用Manage packages对话框。

From the command line you can update packages in the solution to the latest version available from nuget.org.

从命令行可以将解决方案中的包更新到nuget.org上的最新版本。

nuget update YourSolution.sln

Note that this will not run any PowerShell scripts in any NuGet packages.

注意,这不会在任何NuGet包中运行任何PowerShell脚本。

From within Visual Studio you can use the Package Manager Console to also update the packages. This has the benefit that any PowerShell scripts will be run as part of the update where as using NuGet.exe will not run them. The following command will update all packages in every project to the latest version available from nuget.org.

在Visual Studio中,您可以使用包管理器控制台来更新包。这样做的好处是,任何PowerShell脚本都将在使用NuGet时作为更新的一部分运行。exe不会运行它们。下面的命令将把每个项目中的所有包更新到nuget.org的最新版本。

Update-Package

You can also restrict this down to one project.

您还可以将其限制为一个项目。

Update-Package -Project YourProjectName

If you want to reinstall the packages to the same versions as were previously installed then you can use the -reinstall argument with Update-Package command.

如果希望将包重新安装到以前安装的相同版本,那么可以使用-reinstall参数和Update-Package命令。

Update-Package -reinstall

You can also restrict this down to one project.

您还可以将其限制为一个项目。

Update-Package -reinstall -Project YourProjectName

The -reinstall option will first uninstall and then install the package back again into a project.

“重新安装”选项将首先卸载,然后将包重新安装到项目中。

Or, you can update the packages using the Manage Packages dialog.

或者,您可以使用Manage packages对话框更新包。

Updates:

更新:

  • 2013/07/10 - Updated with information about nuget restore in NuGet 2.7
  • 2013/07/10——在nuget 2.7中更新有关nuget恢复的信息
  • 2014/07/06 - Updated with information about automatic package restore in Visual Studio and brought the answer up to date with other changes to NuGet.
  • 2014/07/06——在Visual Studio中更新了关于自动恢复包的信息,并在NuGet中更新了答案。
  • 2014/11/21 - Updated with information about -reinstall
  • 2014/11/21 -更新-重新安装信息

#2


434  

Reinstall all packages in ALL PROJECTS of the current solution:

在当前解决方案的所有项目中重新安装所有包:

Update-Package -Reinstall

Reinstall all packages in SPECIFIC PROJECT of the current solution (Thanks to unarity and ashes999):

在当前解决方案的特定项目中重新安装所有包(感谢unarity和ashes999):

Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall

#3


164  

There is another, newer and quicker way to do this from within Visual Studio. Check out this post by David Ebbo, and reference the comments section if you run into trouble. Basically, you do the following in Package Manager prompt:

在Visual Studio中还有另一种更新、快捷的方法来实现这一点。查看David Ebbo的这篇文章,如果遇到麻烦,请参考评论部分。基本上,您在Package Manager提示符中执行以下操作:

PM> Install-Package NuGetPowerTools
PM> Enable-PackageRestore

Afterwards, when you build your solution the packages will be automatically installed if they're missing.

之后,当您构建您的解决方案时,如果包丢失,将自动安装它们。

Update:

更新:

This functionality is built into Nuget 1.6 with visual studio integration so you don't even need to install NuGetPowerTools or type commands. All you have to do is

这个功能被内置到Nuget 1.6中,并带有visual studio集成,因此您甚至不需要安装NuGetPowerTools或type命令。你所要做的就是

Right click on the Solution node in Solution Explorer and select Enable NuGet Package Restore.

右键单击解决方案资源管理器中的解决方案节点,并选择Enable NuGet包恢复。

Read this article for more details.

更多细节请阅读本文。

#4


18  

Here's another solution if you are using website projects, or don't want to enable NuGet Package restore.

如果您正在使用网站项目,或者不想启用NuGet包恢复,这里有另一个解决方案。

You can use the package manager console to enumerate all the packages in the package.config file and re-install them.

您可以使用包管理器控制台枚举包中的所有包。配置文件并重新安装它们。

# read the packages.config file into an XML object
[xml]$packages = gc packages.config

# install each package 
$packages.packages.package | % { Install-Package -id $($_.id) -Version $($_.version) }

#5


14  

Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall

This is best and easiest example I found. It will reinstall all nugets that are listed in packages.config and it will preserve current versions. Replace YourProjectNameGoesHere with the project name.

这是我找到的最好和最简单的例子。它将重新安装包中列出的所有nuget。配置并保存当前版本。将您的projectnamegoeshere替换为项目名。

#6


10  

With the latest NuGet 2.5 release there is now an "Update All" button in the packages manager: http://docs.nuget.org/docs/release-notes/nuget-2.5#Update_All_button_to_allow_updating_all_packages_at_once

在最新的NuGet 2.5版本中,现在包管理器中有一个“Update All”按钮:http://docs.nuget.org/docs/release-notes/nuget-2.5# update_all_button_allow_updating_allages_at_at_once

#7


5  

I'm using visual studio 2015 and the solutions given above didn't work for me, so i did the following:

我使用的是visual studio 2015,上面给出的解决方案对我不起作用,所以我做了如下的事情:

Delete the packages folder from my solution and also bin and obj folders from every project in the solution and give it a rebuild.

从我的解决方案中删除package文件夹,并从解决方案中的每个项目中删除bin和obj文件夹,并对其进行重新构建。

Maybe you will have the next error:

也许你会有下一个错误:

unable to locate nuget.exe

无法找到nuget.exe

To solve this: Change this line in your NuGet.targets file and setting it to true:

要解决这个问题:在你的NuGet中改变这条线。目标文件并将其设置为true:

<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>

Reference:https://*.com/a/30918648 and https://*.com/a/20502049

参考:https://*.com/a/30918648和https://*.com/a/20502049

#8


3  

I believe the first thing you need to do is enable the package restore feature. See also here. This is done at the solution (not project) level.

我相信您需要做的第一件事是启用包恢复功能。参见这里。这是在解决方案(而不是项目)级别上完成的。

But that won't get you all the way -- I ran into a similar issue after having enabled the restore feature. (VS2013, NuGet 2.8.)

但这并不能完全解决问题——我在启用恢复功能后遇到了类似的问题。(VS2013 NuGet 2.8。)

It turned out I had (unintentionally) committed the packages to source control when I committed the project -- but Visual Studio (and the source control plugin) had helpfully ignored the binaries when performing the check-in.

结果证明,当我提交项目时(无意中)我将包提交给了源代码控制——但是Visual Studio(和源代码控制插件)在执行签入时有效地忽略了二进制文件。

The problem arose when I created a release branch. My local copy of the dev/main/trunk branch had the binaries, because that's where I had originally installed/downloaded the packages.
However, in the new release branch,

当我创建发布分支时出现了问题。我的dev/main/主干分支的本地副本有二进制文件,因为这是我最初安装/下载包的地方。然而,在新的发布分支中,

  • the package folders and .nupkg files were all there -- so NuGet didn't think there was anything to restore;
  • 包文件夹和.nupkg文件都在那里——所以NuGet不认为有什么要恢复;
  • but at the same time, none of the DLLs were present -- i.e. the third-party references were missing -- so I couldn't build.
  • 但与此同时,没有dll存在——也就是说,没有第三方引用——所以我无法构建。

I deleted all the package folders in $(SolutionDir)/packages (under the release branch) and then ran a full rebuild, and this time the build succeeded.
... and then of course I went back and removed the package folders from source control (in the trunk and release branch). I'm not clear (yet) on whether the repositories.config file should be removed as well.

我删除了$(SolutionDir)/packages(发布分支下)中的所有包文件夹,然后进行了完整的重新构建,这次构建成功了……然后,当然,我返回并从源代码控制(在主干和发布分支中)删除了包文件夹。我还不清楚是否有存储库。配置文件也应该被删除。

Many of the components installed for you by the project templates -- at least for web projects -- are NuGet packages. That is, this issue is not limited to packages you've added.
So enable package restore immediately after creating the project/solution, and before you perform an initial check-in, clear the packages folder (and make sure you commit the .nuget folder to source control).

项目模板为您安装的许多组件(至少对于web项目)是NuGet包。也就是说,这个问题不仅限于您添加的包。因此,在创建项目/解决方案之后立即启用包恢复,在执行初始签入之前,清除包文件夹(并确保将.nuget文件夹提交到源代码控制中)。

Disclaimer: I saw another answer here on SO which indicated that clearing the packages folder was part of the resolution. That put me on the right track, so I'd like to give the author credit, but I can no longer locate that question/answer. I'll post an edit if I stumble across it.

免责声明:我在这里看到了另一个答案,表明清理包文件夹是解决方案的一部分。这让我走上了正确的道路,所以我想给作者加分,但我再也找不到那个问题/答案了。如果我偶然发现它,我会发布一个编辑。

I'd also note that Update-Package -reinstall will modify the .sln and .csproj/.vbproj files. At least that's what it did in my case. Which IMHO makes this option much less attractive.

我还注意到,Update-Package -reinstall将修改.sln和.csproj/。vbproj文件。至少在我的例子里是这样的。这使得IMHO这个选项的吸引力大大降低。

#9


3  

After 3 hours of searching and investigation.

经过3小时的搜寻和调查。

I had problems with it because we have two members in team (using GitHub source control), because we didn't restrict files for packages for sending to remote repository, one of team members was send packages to server and i have pull that changes to my local.

我遇到了一些问题,因为我们团队中有两个成员(使用GitHub源代码控制),因为我们没有限制将包发送到远程存储库的文件,其中一个团队成员将包发送到服务器,我已经将这些更改拖到本地。

After that i had same problem as PO, also i wasn't be able to publish my API project to server.

在此之后,我遇到了与PO相同的问题,我也无法将我的API项目发布到服务器上。

At the and I have just used

我刚刚用过

Update-Package -Reinstall - run this command on Package Manager Console

更新包-重新安装-在包管理器控制台上运行这个命令。

This command will reinstall all your packages that you have used in your solution. (For every project)

此命令将重新安装您在解决方案中使用的所有包。(每个项目)

Reinstall all packages in ALL PROJECTS of the current solution:

在当前解决方案的所有项目中重新安装所有包:

Update-Package -ProjectName 'NameOfProject' -Reinstall - run this command on Package Manager Console

Update-Package - projectname 'NameOfProject' - reinstall -在Package Manager控制台运行这个命令

This command will reinstall all your packages that are in relation with project that you specified after "-ProjectName". And i think that this is better because i had wait for half a hour to reinstall all packages in solution.

此命令将重新安装与您在“-ProjectName”之后指定的项目相关的所有包。我认为这样更好,因为我已经等了半个小时来重新安装解决方案中的所有包。

For this many thanks to Rodolpho Brock.

感谢罗道夫·布洛克。

Also, I would recommend you that when you pull changes from remote server, to press "Restore packages" button that will be shown by Visual studio.

另外,我建议您在从远程服务器提取更改时,按一下Visual studio将显示的“恢复包”按钮。

#10


2  

For those arriving here due to the build server falling foul of this, you can create an MSBuild target running the exec command to run the nuget restore command, as below (in this case nuget.exe is in the .nuget folder, rather than on the path), which can then be run in a TeamCity build step immediately prior to building the solution

对于由于构建服务器出现问题而到达这里的用户,可以创建一个MSBuild目标,运行exec命令来运行nuget恢复命令,如下所示(在本例中为nuget)。exe位于.nuget文件夹中,而不是路径中),然后可以在构建解决方案之前立即在TeamCity构建步骤中运行

<Target Name="BeforeBuild">
  <Exec Command="..\.nuget\nuget restore ..\MySolution.sln"/>
</Target>

#11


2  

If you Nuget 2.8 install, check the checkbox

如果您使用Nuget 2.8安装,请选中复选框

Tools >> Nuget Manager >> Package Manager Settings >> Automatically check for missing packages during build

in Visual Studio. If it is checked, then simply rebuild the project will restore all your reference libraries.

在Visual Studio。如果选中它,那么只需重新构建项目就可以恢复所有的参考库。

#12


1  

now Nuget Package Manager Console in Visual Studio 2012 gives you a "Restore" button automatically as soon it find any package not installed but in there in package.config. Awesome Feature!

现在,Visual Studio 2012中的Nuget包管理器控制台会自动为您提供一个“恢复”按钮,当它发现没有安装任何包时,它会在Package .config中。很棒的功能!

#13


1  

At VS2012 V11, if I use "-Reinstall" at the end of the line it doesn't work.

在VS2012 V11中,如果我在行尾使用“-Reinstall”,它就不能工作。

So I simply used:

所以我仅仅使用:

Update-Package -ProjectName 'NAME_OF_THE_PROJECT'

#14


1  

I know this is an old post, but thought this could be useful. If you have a need to ignore specific packages during the update process (like any packages that update JavaScript references), use the following PowerShell script (make sure your package source is set to "All" in Package Manager Console):

我知道这是一个旧帖子,但认为这可能有用。如果在更新过程中需要忽略特定的包(如任何更新JavaScript引用的包),请使用以下PowerShell脚本(请确保在包管理器控制台将包源设置为“All”):

EDIT 2014-09-25 10:55 AM EST - Fixed a bug in the script

编辑2014-09-25上午10:55 EST -修复了脚本中的一个错误

$packagePath = "packages.config"
$projectName = "MyProjectName"

$packagesToIgnore = @(
    "bootstrap",
    "jQuery",
    "jquery-globalize",
    "jquery.mobile",
    "jQuery.jqGrid",
    "jQuery.UI.Combined",
    "jQuery.Validation",
    "Microsoft.jQuery.Unobtrusive.Validation",
    "Modernizr",
    "Moment.js"
)

[xml]$packageFile = gc $packagePath
$packagesToProcess = $packageFile.packages.package | Where-Object {$packagesToIgnore -notcontains $_.id}

$packagesToProcess | % { Update-Package -reinstall -projectname $projectName -id $($_.id) }

#15


0  

In Visual Studio 2017 - When you compile using IDE - It will download all the missing nuget packages and save in the folder "packages".

在Visual Studio 2017——当您使用IDE编译时——它将下载所有丢失的nuget包并保存到“packages”文件夹中。

But on the build machine compilation was done using msbuild.exe. In that case, I downloaded nuget.exe.

但是在构建机器上,编译是使用msbuild.exe完成的。在这种情况下,我下载了nuget.exe。

During each build process before executing msbuild.exe. It will execute -> nuget.exe restore NAME_OF_SLN_File (if there is only one .SLN file then you can ignore that parameter).

在执行msbuild.exe之前的每个构建过程中。它将执行-> nuget。exe还原NAME_OF_SLN_File(如果只有一个. sln文件,则可以忽略该参数)。