Skip to content

Make PowerShell script invocation more reliable#46729

Open
flcdrg wants to merge 1 commit into
microsoft:mainfrom
flcdrg:powershell-hardening
Open

Make PowerShell script invocation more reliable#46729
flcdrg wants to merge 1 commit into
microsoft:mainfrom
flcdrg:powershell-hardening

Conversation

@flcdrg
Copy link
Copy Markdown

@flcdrg flcdrg commented Apr 2, 2026

Summary of the Pull Request

  • Protect against issues caused by loading PowerShell profile scripts
  • Ignore any warnings that may be generated by auto-loaded PowerShell modules. Warnings are written to stderr which the Exec then interprets as an error

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

The build contains PowerShell invocations. The issue with these prior to this change is that they are vulnerable to what ever may be in the current user's PowerShell profile script.

They are also vulnerable to any auto-loaded PowerShell modules that may generate warnings, as the warning output is interpreted as an error by the MSBuild Exec task.

Validation Steps Performed

  1. Built successfully from command line and in Visual Studio
  2. Tested locally and also tested MouseWithoutBorders against second machine.

@flcdrg flcdrg force-pushed the powershell-hardening branch from 29c5aa8 to 1c9a591 Compare April 2, 2026 06:52
@flcdrg flcdrg marked this pull request as ready for review April 2, 2026 07:16
@flcdrg flcdrg force-pushed the powershell-hardening branch 2 times, most recently from d108e74 to 77eab34 Compare April 4, 2026 02:38
@flcdrg flcdrg force-pushed the powershell-hardening branch 2 times, most recently from 6469f9e to 50ea894 Compare April 26, 2026 08:48
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the build’s PowerShell-based resource-generation steps to avoid failures caused by user PowerShell profiles and noisy warning output during MSBuild Exec invocations.

Changes:

  • Updates many GenerateResourceFiles MSBuild targets to invoke powershell with -NoProfile -NonInteractive and an inline command wrapper.
  • Suppresses PowerShell warning stream output during these invocations via $WarningPreference='SilentlyContinue'.
  • Updates localization documentation to reflect the new recommended MSBuild Exec command pattern.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/runner/runner.vcxproj Updates PowerShell invocation used for runner resource generation.
src/modules/previewpane/powerpreview/powerpreview.vcxproj Updates PowerShell invocation for PowerPreview resource generation.
src/modules/previewpane/MarkdownPreviewHandlerCpp/MarkdownPreviewHandlerCpp.vcxproj Updates PowerShell invocation for Markdown preview handler resources.
src/modules/powerrename/dll/PowerRenameExt.vcxproj Updates PowerShell invocation for PowerRenameExt resources.
src/modules/powerrename/PowerRenameContextMenu/PowerRenameContextMenu.vcxproj Updates PowerShell invocation for PowerRename context menu resources.
src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.vcxproj Updates PowerShell invocation for Launcher resources.
src/modules/keyboardmanager/dll/KeyboardManager.vcxproj Re-formats project XML and updates PowerShell invocation for resource generation.
src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerEditorLibrary.vcxproj Updates PowerShell invocation for KeyboardManager editor resources.
src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj Updates PowerShell invocation for KeyboardManager editor resources.
src/modules/keyboardmanager/Directory.Build.targets Updates module-wide PowerShell invocation for KeyboardManager resource generation.
src/modules/imageresizer/dll/ImageResizerExt.vcxproj Updates PowerShell invocation for ImageResizerExt resources.
src/modules/imageresizer/ImageResizerContextMenu/ImageResizerContextMenu.vcxproj Updates PowerShell invocation for ImageResizer context menu resources.
src/modules/fancyzones/FancyZonesLib/FancyZonesLib.vcxproj Updates PowerShell invocation for FancyZones resources.
src/modules/colorPicker/ColorPicker/ColorPicker.vcxproj Updates PowerShell invocation for ColorPicker resources.
src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.vcxproj Updates PowerShell invocation for AlwaysOnTop resources.
src/modules/Workspaces/WorkspacesWindowArranger/WorkspacesWindowArranger.vcxproj Updates PowerShell invocation for Workspaces Window Arranger resources.
src/modules/Workspaces/WorkspacesSnapshotTool/WorkspacesSnapshotTool.vcxproj Updates PowerShell invocation for Workspaces Snapshot Tool resources.
src/modules/Workspaces/WorkspacesLauncher/WorkspacesLauncher.vcxproj Updates PowerShell invocation for Workspaces Launcher resources.
src/modules/ShortcutGuide/ShortcutGuideModuleInterface/ShortcutGuideModuleInterface.vcxproj Updates PowerShell invocation for ShortcutGuide module interface resources.
src/modules/ShortcutGuide/ShortcutGuide/ShortcutGuide.vcxproj Updates PowerShell invocation for ShortcutGuide resources.
src/modules/PowerOCR/PowerOCRModuleInterface/PowerOCRModuleInterface.vcxproj Updates PowerShell invocation for PowerOCR module interface resources.
src/modules/NewPlus/NewShellExtensionContextMenu/NewShellExtensionContextMenu.vcxproj Updates PowerShell invocation for NewPlus shell extension resources.
src/modules/NewPlus/NewShellExtensionContextMenu.win10/NewPlus.ShellExtension.win10.vcxproj Updates PowerShell invocation for NewPlus Win10 shell extension resources.
src/modules/Hosts/HostsModuleInterface/HostsModuleInterface.vcxproj Updates PowerShell invocation for Hosts module interface resources.
src/modules/FileLocksmith/FileLocksmithExt/FileLocksmithExt.vcxproj Updates PowerShell invocation for FileLocksmith extension resources.
src/modules/FileLocksmith/FileLocksmithContextMenu/FileLocksmithContextMenu.vcxproj Updates PowerShell invocation for FileLocksmith context menu resources.
src/modules/EnvironmentVariables/EnvironmentVariablesModuleInterface/EnvironmentVariablesModuleInterface.vcxproj Updates PowerShell invocation for Environment Variables module interface resources.
src/modules/AdvancedPaste/AdvancedPasteModuleInterface/AdvancedPasteModuleInterface.vcxproj Updates PowerShell invocation for AdvancedPaste module interface resources.
src/Update/PowerToys.Update.vcxproj Updates PowerShell invocation for Update component resources.
src/ActionRunner/actionRunner.vcxproj Updates PowerShell invocation for ActionRunner resources.
doc/devdocs/development/localization.md Updates guidance/sample command for C++ localization resource generation.

Comment thread src/runner/runner.vcxproj Outdated
Comment thread src/modules/previewpane/powerpreview/powerpreview.vcxproj Outdated
Comment thread doc/devdocs/development/localization.md
MuyuanMS added a commit to flcdrg/PowerToys that referenced this pull request Apr 28, 2026
…#46729)

Address Copilot review: quote $(MSBuildThisFileDirectory) and similar
MSBuild path variables with single quotes inside -Command strings to
prevent argument splitting when paths contain spaces or special characters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated 28 comments.

Comment thread src/modules/imageresizer/ImageResizerContextMenu/ImageResizerContextMenu.vcxproj Outdated
Comment thread src/modules/Workspaces/WorkspacesLauncher/WorkspacesLauncher.vcxproj Outdated
Comment thread src/modules/launcher/Microsoft.Launcher/Microsoft.Launcher.vcxproj Outdated
Comment thread src/modules/keyboardmanager/Directory.Build.targets
Comment thread src/modules/Workspaces/WorkspacesWindowArranger/WorkspacesWindowArranger.vcxproj Outdated
Comment thread src/modules/powerrename/PowerRenameContextMenu/PowerRenameContextMenu.vcxproj Outdated
Comment thread src/modules/Hosts/HostsModuleInterface/HostsModuleInterface.vcxproj Outdated
Comment thread src/Update/PowerToys.Update.vcxproj Outdated
Comment thread src/modules/imageresizer/dll/ImageResizerExt.vcxproj Outdated
@flcdrg flcdrg force-pushed the powershell-hardening branch from 4e6b8c1 to 972ae65 Compare April 29, 2026 07:28
@flcdrg
Copy link
Copy Markdown
Author

flcdrg commented Apr 29, 2026

Changed to disabling auto-loading of PowerShell modules (rather than just suppressing warnings), and quoting the $(MSBuildThisFileDirectory) (as suggested by Copilot)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated no new comments.

@niels9001 niels9001 added the Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager label Apr 29, 2026
@flcdrg flcdrg force-pushed the powershell-hardening branch 3 times, most recently from e26518e to 01a9bd2 Compare May 4, 2026 23:11
@flcdrg flcdrg force-pushed the powershell-hardening branch 2 times, most recently from b4d6e34 to 888bfb8 Compare May 18, 2026 22:58
- Protect against issues caused from loading default profile
- Don't auto-load modules. Mitigate when unrelated auto-loaded modules may output warnings. As warnings are written to stderr, Exec then interprets that as an error and breaks the build.
- Explicitly load necessary modules in convert-resx-to-rc.ps1

Fixes microsoft#46618
@flcdrg flcdrg force-pushed the powershell-hardening branch from 888bfb8 to 79f2af8 Compare May 19, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build fails with errors 'The command "powershell xxxxxx" exited with code 1'

3 participants