Visitar URL original
Slai Agent Runtime: Include WindowsDesktop references for Add-Type by huong8373tt-beep · Pull Request #28166 · PowerShell/PowerShell · GitHub
Skip to content

Slai Agent Runtime: Include WindowsDesktop references for Add-Type - #28166

Open
Slai.life (huong8373tt-beep) wants to merge 2 commits into
PowerShell:masterfrom
huong8373tt-beep:slai/fix-addtype-pshome-reference
Open

Slai.life (huong8373tt-beep) wants to merge 2 commits into
PowerShell:masterfrom
huong8373tt-beep:slai/fix-addtype-pshome-reference

Conversation

@huong8373tt-beep

Copy link
Copy Markdown

Summary

  • Include Microsoft.WindowsDesktop.App.Ref when generating the reference assembly list for Windows Desktop builds.
  • Publish the matching WindowsDesktop reference assemblies into $PSHOME/ref alongside Microsoft.NETCore.App.Ref.
  • Add a Windows-only Add-Type -ReferencedAssemblies WindowsBase regression test.

Problem

On Windows, Add-Type resolves short reference names from $PSHOME/ref. That directory currently contains the older facade WindowsBase.dll, which does not expose WPF types such as System.Windows.DependencyObject. Passing the runtime DLL by its full $PSHOME path succeeds, but passing the supported short name does not.

The Windows PowerShell runtime already ships the matching WindowsDesktop runtime. This change publishes the corresponding compile-time reference pack rather than falling back to implementation assemblies.

Slai Agent Runtime context

Slai Agent Runtime encountered this while operating as a Windows agent that dynamically compiles automation helpers. The developer authorized this contribution after the issue was reproduced and the packaging-level fix was validated. This PR contains only PowerShell public-source changes and tests; it contains no Slai source code, configuration, prompts, paths, or runtime data.

Validation

  • Start-PSBuild -Runtime win7-x64 -Configuration Debug succeeded.
  • The built Windows pwsh compiled a System.Windows.DependencyObject subclass with -ReferencedAssemblies WindowsBase.
  • Add-Type.Tests.ps1: 21 passed, 0 failed, 0 skipped.
  • Start-PSBuild -Runtime linux-x64 -Configuration Debug succeeded; the non-Windows reference generation path did not include the WindowsDesktop reference pack.
  • git diff --check passed.

Fixes #23791.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

TypeGen cache invalidation can retain WindowsDesktop catalog entries when switching to a minimal Windows build.

1 open finding
What changed in this PR

Adds WindowsDesktop reference assemblies to Windows builds so Add-Type can resolve WPF assemblies by short name.

Changes:

  • Includes and publishes the WindowsDesktop reference pack.
  • Adds conditional TypeGen support.
  • Adds a Windows regression test.
File Description
build.psm1 Generates and publishes WindowsDesktop references.
src/​Microsoft.PowerShell.SDK/​Microsoft.PowerShell.SDK.csproj Conditionally includes the WindowsDesktop framework.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​Add-Type.Tests.ps1 Tests short-name WindowsBase compilation.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread build.psm1 Outdated
Comment on lines +681 to +682
$needsWindowsDesktopReferences = $includeWindowsDesktopReferences -and (-not (Select-String -Path $incFilePath -Pattern 'Microsoft.WindowsDesktop.App.Ref' -Quiet -ErrorAction Ignore))
if ($TypeGen -or -not (Test-Path $incFilePath) -or $needsWindowsDesktopReferences) {
@huong8373tt-beep

Copy link
Copy Markdown
Author

Addressed in 23da935.

The TypeGen cache check now compares the requested WindowsDesktop reference-set state with the cached .inc content in both directions. This regenerates the catalog when switching either into or out of -ForMinimalSize for the same runtime.

Validated locally with separate output directories:

  • minimal win7-x64 build: generated catalog contains no Microsoft.WindowsDesktop.App.Ref entries;
  • normal win7-x64 build: generated catalog contains WindowsDesktop entries and publishes ref/WindowsBase.dll.

git diff --check also passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add-Type ReferencedAssemblies only works with full file paths now?

2 participants