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. 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