Feature Request '-Force' Argument to Update-Package Cmd-Let

Jan 17, 2012 at 9:04 PM

What about if a developer want to back to a previous version of a 'Sample.Package' if he already update to a new one. 

Beta package may contains several errors, and may contains more errors than it's previous beta version (unusual but possible).

So, if a developer want to go back to a previous version of a package and try this:      

Update-Package Sample.Package -Version 2.1.3-beta -IncludePrerelease

with the Sample.Package 2.1.4-beta installed, for example, an error is raised with this message:

      Update-Package : Already referencing a newer version of 'Sample.Package'

So, if a "-Force" argument is included developers can go back fast to a previous version of a package.

Update-Package Sample.Package -Version 2.1.3-beta -IncludePrerelease -Force

Are there  an option to go back to a previous package with a single command line?

Jan 17, 2012 at 9:12 PM

I believe we already have a open issue for this. Currently there is no single command line to do this. You have to uninstall the current version and then install the older version.

Jan 18, 2012 at 4:33 PM
Ok, thanks.
Meanwhile developers interested in this feature can use this: 
function Force-Update-Package([string]$Id, [string]$Version, [Switch]$IncludePrerelease)
	$projectsToRestore = New-Object System.Collections.ArrayList

	$projects = Get-Project -All
	foreach($project in $projects)
		echo $project.ProjectName
  		$package = Get-Package -ProjectName $project.ProjectName -ErrorAction SilentlyContinue | Where-Object { $_.Id -eq $Id }
		if($package -ne $null)
			Uninstall-Package $Id -ProjectName $project.ProjectName -Force 

	foreach($project in $projectsToRestore)
		Install-Package $Id -ProjectName $project.ProjectName -Version $Version -IncludePrerelease:$IncludePrerelease