From 9bccc738d48deed012b93af8b36b98c786d8e001 Mon Sep 17 00:00:00 2001 From: wangluoye <294879785+huong8373tt-beep@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:16:30 +0800 Subject: [PATCH 1/2] Respect WhatIf in PowerShell package commands --- .../CommonFiles/PowerShellCmdlet.cs | 11 +++--- .../tests/Microsoft.WinGet.Client.Tests.ps1 | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/PowerShell/CommonFiles/PowerShellCmdlet.cs b/src/PowerShell/CommonFiles/PowerShellCmdlet.cs index 038dd90091..ac4d7ba6f4 100644 --- a/src/PowerShell/CommonFiles/PowerShellCmdlet.cs +++ b/src/PowerShell/CommonFiles/PowerShellCmdlet.cs @@ -502,13 +502,12 @@ internal void SetVariable(string variableName, object value) /// If the operation should continue. internal bool ShouldProcess(string target) { - // If not on the main thread just continue. - if (this.pwshThread != Thread.CurrentThread) + bool shouldProcess = false; + this.ExecuteInPowerShellThread(() => { - return true; - } - - return this.psCmdlet.ShouldProcess(target); + shouldProcess = this.psCmdlet.ShouldProcess(target); + }); + return shouldProcess; } private void Complete() diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 index e864171e80..4dfca7902a 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -298,11 +298,34 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { } } + It 'Does not install with WhatIf' { + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' -WhatIf + + $result | Should -BeNullOrEmpty + (Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller -ErrorAction SilentlyContinue) | Should -BeNullOrEmpty + } + It 'Install by Id' { $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' Validate-WinGetPackageOperationResult $result $expectedExeInstallerResult 'install' } + It 'Does not update with WhatIf' { + $installedVersion = (Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller).InstalledVersion + $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller -WhatIf + + $result | Should -BeNullOrEmpty + (Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller).InstalledVersion | Should -Be $installedVersion + } + + It 'Does not uninstall with WhatIf' { + $installedVersion = (Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller).InstalledVersion + $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller -WhatIf + + $result | Should -BeNullOrEmpty + (Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller).InstalledVersion | Should -Be $installedVersion + } + It 'Install by exact Name and Version' { $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -MatchOption Equals Validate-WinGetPackageOperationResult $result $expectedPortableInstallerResult 'install' @@ -369,6 +392,14 @@ Describe 'Install|Repair|Uninstall-WinGetPackage' { Validate-WinGetPackageOperationResult $result $expectedResult 'install' } + It 'Does not repair MSIX with WhatIf' { + $installedVersion = (Get-WinGetPackage -Id AppInstallerTest.TestMsixInstaller).InstalledVersion + $result = Repair-WinGetPackage -Id AppInstallerTest.TestMsixInstaller -WhatIf + + $result | Should -BeNullOrEmpty + (Get-WinGetPackage -Id AppInstallerTest.TestMsixInstaller).InstalledVersion | Should -Be $installedVersion + } + It 'Repair MSIX By Id' { $result = Repair-WinGetPackage -Id AppInstallerTest.TestMsixInstaller Validate-WinGetPackageOperationResult $result $expectedResult 'repair' @@ -594,6 +625,14 @@ Describe 'Export-WinGetPackage' { AddTestSource } + It 'Does not download with WhatIf' { + $testDirectory = GetRandomTestDirectory + $result = Export-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' -DownloadDirectory $testDirectory -WhatIf + + $result | Should -BeNullOrEmpty + Test-Path -Path $testDirectory | Should -Be $false + } + It 'Download by Id' { $testDirectory = GetRandomTestDirectory $result = Export-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' -DownloadDirectory $testDirectory From fef0e8040a55ad4b20f58b8338f2f89655431992 Mon Sep 17 00:00:00 2001 From: wangluoye <294879785+huong8373tt-beep@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:20:46 +0800 Subject: [PATCH 2/2] Add WhatIf release note --- doc/ReleaseNotes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/ReleaseNotes.md b/doc/ReleaseNotes.md index 151f337e5b..80ac308011 100644 --- a/doc/ReleaseNotes.md +++ b/doc/ReleaseNotes.md @@ -45,6 +45,10 @@ For aliases requested through `--rename`, `Commands`, or `PortableCommandAlias`, This change resolves alias failures in non-symlinked scenarios, including cases where WinGet adds the install directory to `PATH` instead of creating links. Because the alias is now created as an executable hardlink in the install location, command aliases remain available and consistent even when symlink creation is skipped. +### PowerShell `-WhatIf` + +PowerShell package commands now honor `-WhatIf` and do not perform package operations during preview. + ### Minor Bug Fixes * Fixed REST search results bypassing locally verifiable package filters and selectors. Extra manifests are retrieved only for complete source result sets of three or fewer packages. Normalized name/publisher criteria remain unvalidated client-side. * Fixed installed-package matching incorrectly combining names and publishers from different manifest entries.