program tip

NuGet에서 packages.config의 모든 패키지를 설치 / 업데이트하려면 어떻게하나요?

radiobox 2020. 10. 2. 21:58
반응형

NuGet에서 packages.config의 모든 패키지를 설치 / 업데이트하려면 어떻게하나요?


여러 프로젝트가 포함 된 솔루션이 있습니다. 대부분의 타사 참조가 누락되었지만 packages.config각 프로젝트에 대한 파일 이 있습니다 . NuGet에서 필요한 모든 패키지를 설치 / 업데이트하려면 어떻게해야하나요? 각 프로젝트의 명령 줄을 통해이 작업을 수행해야합니까?


nuget.exe사용 하여 패키지를 복원하거나 NuGet 2.7 이상이 설치된 상태에서 Visual Studio에서 솔루션을 간단히 컴파일하여 누락 된 패키지도 복원 할 수 있습니다.

NuGet.exe의 경우 각 프로젝트에 대해 다음 명령을 실행할 수 있습니다.

nuget install packages.config

또는 NuGet 2.7을 사용하면 명령 줄을 사용하여 솔루션의 모든 패키지를 복원 할 수 있습니다 .

nuget restore YourSolution.sln

이 두 가지 모두 패키지를 가져옵니다. 그러나이 명령을 실행할 때 프로젝트 파일은 수정되지 않으므로 프로젝트에 NuGet 패키지에 대한 참조가 이미 있어야합니다. 그렇지 않은 경우 Visual Studio를 사용하여 패키지를 설치할 수 있습니다.

NuGet 2.7 이상에서는 솔루션을 빌드 할 때 Visual Studio가 누락 된 NuGet 패키지를 자동으로 복원하므로 NuGet.exe를 사용할 필요가 없습니다.

솔루션의 모든 패키지를 업데이트하려면 먼저 패키지를 복원 한 다음 NuGet.exe를 사용하여 패키지를 업데이트하거나 Visual Studio 내에서 패키지 관리자 콘솔 창에서 패키지를 업데이트하거나 마지막으로 관리를 사용할 수 있습니다. 패키지 대화 상자.

명령 줄에서 솔루션의 패키지를 nuget.org에서 사용 가능한 최신 버전으로 업데이트 할 수 있습니다.

nuget update YourSolution.sln

NuGet 패키지에서 PowerShell 스크립트는 실행되지 않습니다.

Visual Studio 내에서 패키지 관리자 콘솔사용하여 패키지 를 업데이트 할 수도 있습니다. 이는 모든 PowerShell 스크립트가 NuGet.exe를 사용할 때 실행되지 않는 업데이트의 일부로 실행된다는 이점이 있습니다. 다음 명령은 모든 프로젝트의 모든 패키지를 nuget.org에서 사용 가능한 최신 버전으로 업데이트합니다.

Update-Package

이를 하나의 프로젝트로 제한 할 수도 있습니다.

Update-Package -Project YourProjectName

이전에 설치된 것과 동일한 버전으로 패키지를 다시 설치하려면 command -reinstall와 함께 인수를 사용할 수 있습니다 Update-Package.

Update-Package -reinstall

이를 하나의 프로젝트로 제한 할 수도 있습니다.

Update-Package -reinstall -Project YourProjectName

-reinstall옵션은 먼저 패키지를 제거한 다음 프로젝트에 다시 설치합니다.

또는 Manage Packages대화 상자를 사용하여 패키지를 업데이트 할 수 있습니다 .

업데이트 :

  • 2013 / 07 / 10 -NuGet 2.7의 Nuget 복원에 대한 정보로 업데이트 됨
  • 2014 / 07 / 06 -Visual Studio의 자동 패키지 복원에 대한 정보로 업데이트되었으며 NuGet의 다른 변경 사항에 대한 답변을 최신 상태로 가져 왔습니다.
  • 2014 / 11 / 21-다음 에 대한 정보로 업데이트 됨-reinstall

현재 솔루션의 모든 프로젝트에있는 모든 패키지를 다시 설치합니다.

Update-Package -Reinstall

현재 솔루션의 SPECIFIC PROJECT에있는 모든 패키지를 다시 설치합니다 ( unarityashes999 덕분에 ) :

Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall

Visual Studio 내에서이 작업을 수행하는 또 다른 새롭고 빠른 방법이 있습니다. David Ebbo 의이 게시물확인하고 문제가 발생하면 주석 섹션을 참조하십시오. 기본적으로 패키지 관리자 프롬프트에서 다음을 수행합니다.

PM> Install-Package NuGetPowerTools
PM> Enable-PackageRestore

나중에 솔루션을 빌드 할 때 패키지가 누락 된 경우 자동으로 설치됩니다.

최신 정보:

이 기능은 Visual Studio가 통합 된 Nuget 1.6에 내장되어 있으므로 NuGetPowerTools 를 설치하거나 명령을 입력 할 필요도 없습니다. 당신이해야 할 일은

솔루션 탐색기에서 솔루션 노드를 마우스 오른쪽 단추로 클릭하고 NuGet 패키지 복원 활성화를 선택합니다.

자세한 내용은 이 기사읽으십시오 .


웹 사이트 프로젝트를 사용 중이거나 NuGet 패키지 복원을 사용하지 않으려는 경우 다른 솔루션이 있습니다.

패키지 관리자 콘솔을 사용하여 package.config 파일의 모든 패키지를 열거하고 다시 설치할 수 있습니다.

# 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) }

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.


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


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

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

Maybe you will have the next error:

unable to locate nuget.exe

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

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

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


If you Nuget 2.8 install, check the checkbox

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.


After 3 hours of searching and investigation.

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.

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

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

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.

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.


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.)

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.

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,

  • the package folders and .nupkg files were all there -- so NuGet didn't think there was anything to restore;
  • but at the same time, none of the DLLs were present -- i.e. the third-party references were missing -- so I couldn't build.

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.

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).

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.


I tried Update-Package -reinstall but it fails on a package and stopped processing all remaining packages of projects in my solution.

I ended up with my script that enumerates all package.config files and run Update-Package -Reinstall -ProjectName prj -Id pkg for each project/package.

Hope it can be useful for someone:

$files = Get-ChildItem -Recurse -Include packages.config;

[array]$projectPackages = @();
$files | foreach { [xml]$packageFile = gc $_; $projectName = $_.Directory.Name; $packageFile.packages.package.id | foreach { $projectPackages += @( ,@( $projectName, $_ ) ) } }

$projectPackages | foreach { Update-Package -Reinstall -ProjectName $_[0] -Id $_[1] }

Edit: This is an error that I had: Update-Package : Unable to find package 'EntityFramework.BulkInsert-ef6'. Existing packages must be restored before performing an install or update. Manual run of Update-Package -Reinstall -ProjectName my_prj -Id EntityFramework.BulkInsert-ef6 worked very well.


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

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

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!


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

So I simply used:

Update-Package -ProjectName 'NAME_OF_THE_PROJECT'

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):

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

$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) }

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

But on the build machine compilation was done using msbuild.exe. In that case, I downloaded 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).

참고URL : https://stackoverflow.com/questions/6876732/how-do-i-get-nuget-to-install-update-all-the-packages-in-the-packages-config

반응형