winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Winget Client Powershell - Winget.Client.psm1 Import fails on WinGet preview versions

Open a-mnich opened this issue 4 years ago • 2 comments

Brief description of your issue

The WinGet.Client Powershell Module can not be imported if the installed winget version is a preview version.

Steps to reproduce

  • Install a WinGet preview version
winget --version
v1.2.3411-preview
  • clone winget repository
  • try to import WinGet.Client Powershell module
Import-Module C:\Programming\wingetTest\Microsoft.WinGet.Client.psm1

Expected behavior

successful module import

Actual behavior

Import-Module : Requires Windows Package Manager 1.1.12653 or later to be installed.
In Zeile:1 Zeichen:1
+ Import-Module C:\Programming\wingetTest\Microsoft.WinGet.Client.psm1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Import-Module], WinGetVersionMismatch
    + FullyQualifiedErrorId : Requires Windows Package Manager 1.1.12653 or later to be installed.,Microsoft.PowerShell.Commands.ImportModuleCommand

Environment

Windows Package Manager (Preview) v1.2.3411-preview
Windows: Windows.Desktop v10.0.19043.1415
Package: Microsoft.DesktopAppInstaller v1.17.3411.0

a-mnich avatar Dec 19 '21 13:12 a-mnich

Looks like I found the issue:
The import fails, because an error is thrown in Get-Version.ps1 in the line
$Result = [version](& "winget" $WinGetArgs).trimstart("v") .

The cast of winget --version into an object of type System.Version fails in case of a preview version (e.g. "1.2.3411-preview") as the constructor of System.Version does not accept a string of this format.

A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character ('.'). MS Docs

As a consequence version "0.0.0.0" gets returned by the catch block and WinGet.Client reports a version mismatch.

a-mnich avatar Dec 19 '21 14:12 a-mnich

Good catch! We've recently re-introduced "-preview" at the end of the versioning for preview versions.

denelon avatar Dec 20 '21 17:12 denelon

This issue has been resolved with the latest version of the WinGet Client and the Microsoft.WinGet.Client module.

denelon avatar Mar 06 '24 19:03 denelon