How Can I "Update-Package" to a Previous Version in the Package Manager Console? How Can I "Update-Package" to a Previous Version in the Package Manager Console? powershell powershell

How Can I "Update-Package" to a Previous Version in the Package Manager Console?


I think I already have a solution to this so I place 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 a call such as the following to update all references to a package within 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 the package to be reinstalled even if it has dependent packages within the project.


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

With NuGet 2.8 client or higher, Install-Package can be used to downgrade the existing packages in your project, if necessary. For example, if you had installed a pre-release version of a package to try out new features but would like to go back to a previous stable version you can do so using Install-Package (or Update-Package).


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

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

But then you can Update-Package -Id Foo.Bar -Reinstall and that should reinstall the whole thing with the current dependencies.