How can I upgrade a package to a previous version in the package manager console?

I have a package version installed in my project, but during testing I found a problem with it. I tried the obvious thing Update-Package -Id Foo.Bar -Version 1.0.0 -Force , but the Update-Package cmdlet does not have the -Force parameter and does not allow updating an earlier version. How can I lower my dependencies in a package (without using a control source!)




NOTE. This question doesn't matter now because Update-Package MyPackage -Version [an earlier version] works out of the box in recent versions of NuGet Package Manager. You don't even need the -Force switch.

+49
powershell console nuget nuget-package
Feb 01 2018-12-01T00:
source share
3 answers

I think I already have a solution to this, so I post it here for (constructive) criticism.

 function Reinstall-Package { param( [Parameter(Mandatory = $true)] [string] $Id, [Parameter(Mandatory = $true)] [string] $Version, [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string] $ProjectName, [switch] $Force ) if (-not $ProjectName) { $ProjectName = (get-project).ProjectName } Uninstall-Package -ProjectName $ProjectName -Id $Id -Force:$Force Install-Package -ProjectName $ProjectName -Id $Id -Version $Version } 

This allows us to use the following call to update all package links in the current solution.

  Get-Project -All | ?{ $_ | Get-Package | ?{ $_.Id -eq 'Foo.Bar' } } | %{ $_ | Reinstall-Package -Id Foo.Bar -version 1.0.0 -Force } 

The -Force switch allows you to reinstall a package, even if it has dependent packages in the project.

+35
Feb 01 '12 at 16:47
source share

https://docs.nuget.org/consume/package-manager-console-powershell-reference

With NuGet 2.8 client or higher , Install-Package can be used to downgrade existing packages in your project, if necessary. For example, if you installed a preliminary version of the package to test new features, but would like to return to the previous stable version, you can do this using Install-Package (or Update-Package).

+10
Mar 10 '15 at 8:22
source share

I had Foo.Bar v1 that depended on log4net v2, I needed to lower the log4net dependency to 1.2.10, so I made Foo.Bar v1.1 dependent on log4net v1.2.10.

I found that if you Update-Package Foo.Bar update it to the latest version (it will not reinstall dependencies)

But then you can Update-Package -Id Foo.Bar -Reinstall , and this should reinstall all this with the current dependencies.

+5
Mar 19 '13 at 16:53
source share



All Articles