From 45e8eb8e7417bdc0e2976ee3b2da5c16666cbf24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:10:19 +0000 Subject: [PATCH 1/7] Initial plan From 8878f222fbccb82d23f63cab177525313aa9d08c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:15:04 +0000 Subject: [PATCH 2/7] Initial analysis of uninstall-prerelease issue Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- nuget.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget.config b/nuget.config index 5c704bf46..654858614 100644 --- a/nuget.config +++ b/nuget.config @@ -2,7 +2,7 @@ - + From 26936b2b0d68ccd1fce888a82a9ebe47ee0df4cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:17:13 +0000 Subject: [PATCH 3/7] Add warning when uninstall fails due to version/prerelease filters Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- src/code/UninstallPSResource.cs | 17 +++++++++++++++++ .../UninstallPSResource.Tests.ps1 | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/code/UninstallPSResource.cs b/src/code/UninstallPSResource.cs index 4cd0a4d19..6adfdfeb6 100644 --- a/src/code/UninstallPSResource.cs +++ b/src/code/UninstallPSResource.cs @@ -258,6 +258,23 @@ private bool UninstallPkgHelper(out List errRecords) } } + // If we had packages but didn't uninstall any (e.g., due to version/prerelease filters), write a warning + if (currentUninstalledDirCount == 0 && totalDirs > 0) + { + string warningMessage = Prerelease + ? $"No prerelease versions of '{String.Join(", ", Name)}' were found to uninstall." + : $"No packages matching the specified criteria for '{String.Join(", ", Name)}' were found to uninstall."; + + if (Version != null && !Version.Trim().Equals("*")) + { + warningMessage = Prerelease + ? $"No prerelease versions of '{String.Join(", ", Name)}' matching version '{Version}' were found to uninstall." + : $"No packages of '{String.Join(", ", Name)}' matching version '{Version}' were found to uninstall."; + } + + WriteWarning(warningMessage); + } + return successfullyUninstalled; } diff --git a/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 b/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 index 0a1fa10fc..29b2d8681 100644 --- a/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 @@ -235,6 +235,23 @@ Describe 'Test Uninstall-PSResource for Modules' -tags 'CI' { $stableVersionPkgs.Count | Should -Be 2 } + It "Write warning when using -Prerelease flag with only stable versions installed" { + # Install a stable version + Install-PSResource -Name $testModuleName -Version "5.0.0.0" -Repository $PSGalleryName -TrustRepository + + # Try to uninstall with -Prerelease flag, should show warning + Uninstall-PSResource -Name $testModuleName -Prerelease -SkipDependencyCheck -WarningVariable warn -WarningAction SilentlyContinue + + # Module should still be present + $res = Get-InstalledPSResource -Name $testModuleName -Version "5.0.0.0" + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "5.0.0.0" + + # Warning should have been written + $warn.Count | Should -Be 1 + $warn[0] | Should -Match "No prerelease versions" + } + It "Uninstall module using -WhatIf, should not uninstall the module" { Start-Transcript .\testUninstallWhatIf.txt Uninstall-PSResource -Name $testModuleName -WhatIf -SkipDependencyCheck From c1e94bbf49f74ad52d9ef186af9af8838c282e57 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:21:08 +0000 Subject: [PATCH 4/7] Improve test to use BeforeEach installed module Co-authored-by: alerickson <25858831+alerickson@users.noreply.github.com> --- .../UninstallPSResource.Tests.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 b/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 index 29b2d8681..d479843b0 100644 --- a/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 +++ b/test/UninstallPSResourceTests/UninstallPSResource.Tests.ps1 @@ -236,16 +236,18 @@ Describe 'Test Uninstall-PSResource for Modules' -tags 'CI' { } It "Write warning when using -Prerelease flag with only stable versions installed" { - # Install a stable version - Install-PSResource -Name $testModuleName -Version "5.0.0.0" -Repository $PSGalleryName -TrustRepository + # BeforeEach already installs a stable version of $testModuleName (5.0.0.0) + # Verify it's installed + $pkg = Get-InstalledPSResource $testModuleName + $pkg | Should -Not -BeNullOrEmpty # Try to uninstall with -Prerelease flag, should show warning Uninstall-PSResource -Name $testModuleName -Prerelease -SkipDependencyCheck -WarningVariable warn -WarningAction SilentlyContinue - # Module should still be present - $res = Get-InstalledPSResource -Name $testModuleName -Version "5.0.0.0" + # Module should still be present since no prerelease versions were found + $res = Get-InstalledPSResource -Name $testModuleName + $res | Should -Not -BeNullOrEmpty $res.Name | Should -Be $testModuleName - $res.Version | Should -Be "5.0.0.0" # Warning should have been written $warn.Count | Should -Be 1 From 792b8d807d1a8e6caed3f101ed3169172791c91e Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 8 Oct 2025 12:34:49 -0700 Subject: [PATCH 5/7] Update nuget.config --- nuget.config | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nuget.config b/nuget.config index 654858614..e5700733f 100644 --- a/nuget.config +++ b/nuget.config @@ -2,8 +2,7 @@ - - + From 8c677823e95e11325bb9076a7e8f625ba418dc9d Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:35:54 +0000 Subject: [PATCH 6/7] fix nuget config --- nuget.config | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nuget.config b/nuget.config index e5700733f..d2eb1268d 100644 --- a/nuget.config +++ b/nuget.config @@ -1,9 +1,9 @@ - - + + - + \ No newline at end of file From 5339760b1860854eeb0da23e498ebfc9171b6f52 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:36:44 +0000 Subject: [PATCH 7/7] fix nuget.config again --- nuget.config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nuget.config b/nuget.config index d2eb1268d..5c704bf46 100644 --- a/nuget.config +++ b/nuget.config @@ -1,3 +1,4 @@ + @@ -6,4 +7,4 @@ - \ No newline at end of file +