Skip to content

Commit

Permalink
Fix PSInstalledCatalogPackage being piped to Upgrade-WinGetPackage (#…
Browse files Browse the repository at this point in the history
…3174)

In Update-WinGetPackage, the pipeline can set the PSCatalogPackage can be set by value or property name and the Version by property name.

The result of Get-WinGetPackage piped to Update-WinGetPackage results in both properties being set. In this case, the version is not the desired version to update but the installed version. Internally, when we iterate through all the available versions of the catalog package object we will throw InvalidVersionException because well the version is not available...

To fix it, I renamed the Version property of the PSInstalledCatalogPackage to InstalledVersion to mimic what the underlying catalog package property actually is. This way the version will not be piped into Update-WinGetPackage but the caller can also specify which one it wants to update giving a better experience.
  • Loading branch information
msftrubengu committed Apr 26, 2023
1 parent 9d5cf1c commit f269007
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public string[] AvailableVersions
}
}

/// <summary>
/// Gets the version of the catalog package.
/// </summary>
public abstract string Version { get; }

/// <summary>
/// Gets the catalog package COM object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ internal PSFoundCatalogPackage(CatalogPackage catalogPackage)
{
}

/// <inheritdoc/>
public override string Version
/// <summary>
/// Gets the default install version of the catalog package.
/// </summary>
public string Version
{
get { return this.CatalogPackageCOM.DefaultInstallVersion.Version; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ internal PSInstalledCatalogPackage(CatalogPackage catalogPackage)
{
}

/// <inheritdoc/>
public override string Version
/// <summary>
/// Gets the installed version of the catalog package.
/// </summary>
public string InstalledVersion
{
get { return this.CatalogPackageCOM.InstalledVersion.Version; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<ScriptBlock>$_.Id</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Version</ScriptBlock>
<ScriptBlock>$_.InstalledVersion</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>if ($_.IsUpdateAvailable) { $_.AvailableVersions[0] }</ScriptBlock>
Expand Down

0 comments on commit f269007

Please sign in to comment.