diff --git a/src/code/UpdatePSResource.cs b/src/code/UpdatePSResource.cs index 29792ab71..4d44d2b52 100644 --- a/src/code/UpdatePSResource.cs +++ b/src/code/UpdatePSResource.cs @@ -390,7 +390,8 @@ private string[] ProcessPackageNames( } // If the current package is out of range, install it with the correct version. - if (!NuGetVersion.TryParse(installedPackage.Version.ToString(), out NuGetVersion installedVersion)) + string installedVersionString = Utils.GetThreeDigitNormalizedVersionString(installedPackage.Version.ToString(), installedPackage.Prerelease); + if (!NuGetVersion.TryParse(installedVersionString, out NuGetVersion installedVersion)) { WriteWarning($"Cannot parse nuget version in installed package '{installedPackage.Name}'. Cannot update package."); continue; diff --git a/test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1 b/test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1 index cd50abcf1..e2d81aa65 100644 --- a/test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1 +++ b/test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1 @@ -13,13 +13,14 @@ Describe 'Test HTTP Update-PSResource for V2 Server Protocol' -tags 'CI' { $testModuleName = "test_module" $testModuleName2 = "test_module2" $testModuleName3 = "TestModule99" + $testModuleName4 = "TestModulePrerelease" $PackageManagement = "PackageManagement" Get-NewPSResourceRepositoryFile Get-PSResourceRepository } AfterEach { - Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "test_module2", "test_script" -Version "*" -ErrorAction SilentlyContinue -SkipDependencyCheck + Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "test_module2", "test_script", "TestModulePrerelease" -Version "*" -ErrorAction SilentlyContinue -SkipDependencyCheck } AfterAll { @@ -210,6 +211,20 @@ Describe 'Test HTTP Update-PSResource for V2 Server Protocol' -tags 'CI' { $isPkgUpdated | Should -Be $true } + It "Update prerelease version to next version when prerelease label is only differing factor between versions" { + # $testModuleName4 (TestModulePrerelease) has versions: 0.0.4-beta, 0.0.4. Updating should respect prerelease label + Install-PSResource -Name $testModuleName4 -Version "0.0.4-beta" -Repository $PSGalleryName -TrustRepository + $res = Get-InstalledPSResource -Name $testModuleName4 + $res.Name | Should -Be $testModuleName4 + $res.Version | Should -Contain "0.0.4" + $res.Prerelease | Should -Be "beta" + + Update-PSResource -Name $testModuleName4 -Repository $PSGalleryName -TrustRepository + $res2 = Get-InstalledPSResource -Name $testModuleName4 + $res2.Version | Should -Contain "0.0.4" + $res2.Prerelease | Should -BeNullOrEmpty + } + # Windows only It "update resource under CurrentUser scope" -skip:(!($IsWindows -and (Test-IsAdmin))) { # TODO: perhaps also install TestModule with the highest version (the one above 1.2.0.0) to the AllUsers path too