fix: reset PSModulePath in azd update to prevent PS7/PS5.1 module conflict#7703
fix: reset PSModulePath in azd update to prevent PS7/PS5.1 module conflict#7703hemarina merged 2 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a Windows-specific azd update failure when PowerShell 5.1 is launched from a PowerShell 7 parent shell via cmd.exe /c, causing incompatible module resolution and Get-AuthenticodeSignature failures. It updates the Windows MSI update invocation to ensure Windows PowerShell 5.1 loads the correct module set, and includes a small behavior change in when update configuration is persisted.
Changes:
- Prepend a
PSModulePathreset to the PowerShell command used to download/runinstall-azd.ps1during Windows MSI updates. - Update the
azd updatecommand flow to persist config changes only after a successful update. - Adjust the update design doc guidance for package manager → daily scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cli/azd/pkg/update/msi_windows.go |
Prepends a PowerShell snippet to reset PSModulePath before invoking install-azd.ps1, avoiding PS7/PS5.1 module conflicts. |
cli/azd/cmd/update.go |
Moves config persistence to after a successful update attempt. |
cli/azd/docs/design/azd-update.md |
Updates documented guidance text for package manager → daily messaging. |
jongio
left a comment
There was a problem hiding this comment.
The PSModulePath fix is correct - $PSHOME under PS5.1 correctly resolves to its own modules directory regardless of parent shell. One gap: the existing tests don't verify this prefix is present.
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
jongio
left a comment
There was a problem hiding this comment.
My earlier test coverage comment was addressed - both TestBuildInstallScriptArgs and TestBuildInstallScriptArgs_Structure now verify the PSModulePath reset prefix. The config persistence change is a nice improvement - deferring channel persistence until after a successful update prevents stale config on failed updates, and the non-fatal warning with remediation command is the right call.
One minor gap: the post-update channel-save-failure path (where configManager.Save fails after a successful update) doesn't have a test. There's a failSaveConfigMgr helper in final_coverage3_test.go that could exercise it. Not blocking.
Description
Fixes #7702
When
azd updatespawnspowershell.exe 5.1viacmd.exe /cfrom a PowerShell 7 parent shell (VSCode terminal, Windows Terminal with pwsh), PS5.1 inherits PS7'sPSModulePath. The PS7 Core-editionMicrosoft.PowerShell.Securitymodule is found before the PS5.1 Desktop-edition module, causingGet-AuthenticodeSignatureto fail withCouldNotAutoloadMatchingModule.Root Cause
The exec package forces
cmd.exe /cwrapping on all Windows commands (command_runner.go:99). Thecmd.exeintermediary prevents PS5.1 from detecting that its grandparent is another PowerShell process, so PS5.1 does not override the inheritedPSModulePath. The PS7 module paths (containing Core-only modules) appear before PS5.1 paths, causing incompatible module loading.Fix
Reset
PSModulePathto Windows PowerShell 5.1 defaults inbuildInstallScriptArgs()before invoking the install script. This ensures PS5.1 only sees its own Desktop-edition modules regardless of the parent shell.Testing
Verified by simulating the exact
cmd.exe /c powershell.exeinvocation path from a pwsh parent:cmd.exe /c powershell.exe ... Get-AuthenticodeSignatureCouldNotAutoloadMatchingModuleStatus: Validgo test ./pkg/update/... -run TestBuildInstallScriptArgs