Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/code/UpdatePSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion test/UpdatePSResourceTests/UpdatePSResourceV2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading