суббота, 26 октября 2013 г.

How to revert to the previous version of a nuget package on subset of projects

I was trying to revert nuget package to a previous version. Apparently, this is not an easy task. You can easily update some package to a new version, but if you want to downgrade, you would have to uninstall the old version and then reinstall a specific version. Moreover, if you don't want to install it to all the projects, you would have to remember the project names.

Here is a script that automates this process.
Replace the package name and version and run it in the Package Manager Console.

$packageName = Newtonsoft.Json;
$version = 4.0.5
$projects = Get-Project -all
$projectsWithPackage = new-object System.Collections.ArrayList;
ForEach ($proj in $projects) { Write-Host $project.ProjectName; $projWithPackage = Get-Package -Filter $packageName -ProjectName $proj.ProjectName; if($projWithPackage.Length -gt 0) { $projectsWithPackage.Add($proj.ProjectName) } }
ForEach ($proj in $projectsWithPackage) { Uninstall-Package $packageName -ProjectName $proj -Force}
ForEach ($proj in $projectsWithPackage) { Install-Package $packageName -Version $version -ProjectName $proj }

I haven't figured out how to break long commands to multiple lines, so please feel free to give me your valuable advice. :)

Комментариев нет:

Отправить комментарий