Skip to content

Enable dotnet run for MSIX-packaged MAUI Windows apps - #34606

Closed
mattleibow wants to merge 1 commit into
mainfrom
feature/dotnet-run-msix
Closed

mattleibow wants to merge 1 commit into
mainfrom
feature/dotnet-run-msix

Conversation

@mattleibow

@mattleibow mattleibow commented Mar 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements the DeployToDevice and ComputeRunArguments MSBuild extensibility points from the dotnet-run-for-maui spec, enabling dotnet run to work with WindowsPackageType=MSIX apps that previously required Visual Studio.

dotnet run behavior by WindowsPackageType

WindowsPackageType Before this PR After this PR
None (unpackaged) ✅ Works — runs EXE directly ✅ No change
MSIX (fully packaged) ❌ REGDB_E_CLASSNOTREG crash ✅ Registers package, launches via COM
Sparse (identity only) ✅ Works — runs EXE with external manifest ✅ No change

What each mode means

Unpackaged (None) Sparse MSIX
Package identity ❌ No ✅ Yes ✅ Yes
Runs from build output ✅ Direct EXE ✅ Direct EXE ❌ Must register first
WinRT APIs needing identity ❌ Unavailable ✅ Available ✅ Available
Store distribution ❌ ❌ ✅ Possible
How dotnet run launches RunCommand = EXE RunCommand = EXE RunCommand = dotnet exec tool → COM activation

Before

> dotnet run -f net10.0-windows10.0.19041.0
COMException (0x80040154): Class not registered (REGDB_E_CLASSNOTREG)

After

> dotnet run -f net10.0-windows10.0.19041.0
Registering MSIX package: com.microsoft.maui.sandbox v1.0.0.1 (x64)
Package registered successfully.
Package family: com.microsoft.maui.sandbox_mgjqykre3bqqe
Launching: com.microsoft.maui.sandbox_mgjqykre3bqqe!App
App launched with PID: 44044

What's New

Microsoft.Maui.Windows.Run tool (src/Controls/src/Build.Tasks.Windows.Run/)

A framework-dependent AnyCPU .NET console app that handles MSIX package registration and launch. Runs on both x64 and ARM64 Windows via dotnet exec — no RID-specific builds needed.

  • register: Registers the MSIX package from the loose file layout via PackageManager.RegisterPackageAsync with DevelopmentMode (requires Windows Developer Mode)
  • run: Registers, computes the AUMID, activates the app via IApplicationActivationManager COM interface, waits for process exit, handles Ctrl+C gracefully via IPackageDebugSettings.TerminateAllProcesses
  • Supports --help and --version flags

MSBuild targets (Microsoft.Maui.Windows.Run.targets)

  • DeployToDevice: Calls the tool's register subcommand to register the MSIX package
  • _WindowsMsixComputeRunArguments: Sets RunCommand/RunArguments to launch the registered app via COM activation (BeforeTargets="ComputeRunArguments")
  • All targets conditioned on WindowsPackageType=MSIX — zero impact on unpackaged or sparse apps

Design

Follows the same pattern as Android's Microsoft.Android.Run tool, implementing the extensibility points defined in the dotnet-run-for-maui spec.

Pipeline flow

dotnet run -f net10.0-windows10.0.19041.0
  │
  ├─ Build (existing) → produces AppxManifest.xml + loose layout in bin/
  │
  ├─ DeployToDevice (NEW target)
  │   └─ dotnet exec Microsoft.Maui.Windows.Run.dll register --manifest <path>
  │       → PackageManager.RegisterPackageAsync(manifestUri, DevelopmentMode)
  │       → Package registered from loose files without signing
  │
  ├─ ComputeRunArguments (NEW target, BeforeTargets)
  │   └─ Sets RunCommand = dotnet
  │         RunArguments = exec Microsoft.Maui.Windows.Run.dll run --manifest <path>
  │
  └─ Run (existing SDK target)
      └─ dotnet exec Microsoft.Maui.Windows.Run.dll run --manifest <path>
          → Registers package (idempotent)
          → Reads AppxManifest.xml for Identity + Application Id
          → Queries PackageManager for PackageFamilyName
          → Constructs AUMID = {PackageFamilyName}!{AppId}
          → IApplicationActivationManager.ActivateApplication(AUMID)
          → Waits for process exit
          → Ctrl+C → IPackageDebugSettings.TerminateAllProcesses

Key Windows APIs used

API Purpose
PackageManager.RegisterPackageAsync Register loose MSIX layout (DevelopmentMode)
PackageManager.FindPackagesForUser Query registered package for family name
IApplicationActivationManager.ActivateApplication Launch packaged app by AUMID (COM)
IPackageDebugSettings.TerminateAllProcesses Clean termination on Ctrl+C (COM)

How VS does it (for reference)

Visual Studio uses internal AppxLayoutManager.RegisterPackage() (wraps PackageManager) and the same IApplicationActivationManager COM interface. This implementation follows the same approach but through MSBuild targets and a standalone CLI tool instead of VS-internal APIs.

Also in this PR

  • Tool added to Microsoft.Maui.BuildTasks.slnf and all relevant solution files
  • Tool output + dependencies copied alongside .targets in .buildtasks/ using $(MSBuildThisFileDirectory) pattern
  • Tool DLL + deps packed into Microsoft.Maui.Controls.Build.Tasks NuGet under buildTransitive/net6.0-windows10.0.17763.0/

Prerequisites

  • Windows Developer Mode must be enabled (Settings → System → For Developers). The tool detects this and prints a friendly error if disabled.

TODO (future PRs)

  • Console output / debug log forwarding (no Windows equivalent of Android logcat)

Copilot AI review requested due to automatic review settings March 23, 2026 18:13
@github-actions

github-actions Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34606

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34606"

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.

Pull request overview

Adds a Windows-specific dotnet run pathway for MSIX-packaged MAUI apps by importing new MSBuild targets that (1) register the loose MSIX layout and (2) set RunCommand/RunArguments to activate the app via a new helper tool.

Changes:

  • Introduces Microsoft.Maui.Windows.Run.targets to implement DeployToDevice and ComputeRunArguments for WindowsPackageType=MSIX.
  • Imports the new targets from Microsoft.Maui.Sdk.Windows.targets when building packaged Windows apps.
  • Adds the Microsoft.Maui.Windows.Run console tool that registers MSIX packages and activates them via COM, with Ctrl+C termination support.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Controls/src/Build.Tasks/nuget/buildTransitive/net6.0-windows10.0.17763.0/Microsoft.Maui.Windows.Run.targets New buildTransitive targets that hook dotnet run deploy + run argument computation for MSIX.
src/Controls/src/Build.Tasks/nuget/buildTransitive/net6.0-windows10.0.17763.0/Microsoft.Maui.Sdk.Windows.targets Imports the new MSIX run targets when WindowsPackageType=MSIX.
src/Controls/src/Build.Tasks.Windows.Run/Controls.Build.Tasks.Windows.Run.csproj Adds the new Windows run tool project.
src/Controls/src/Build.Tasks.Windows.Run/Program.cs CLI entrypoint parsing and command routing (register/run).
src/Controls/src/Build.Tasks.Windows.Run/PackageRegistrar.cs MSIX loose-layout registration implementation via PackageManager.
src/Controls/src/Build.Tasks.Windows.Run/AppxManifestReader.cs Parses required identity/app info from AppxManifest.xml.
src/Controls/src/Build.Tasks.Windows.Run/AppActivator.cs COM activation + wait-for-exit and Ctrl+C termination logic.
src/Controls/src/Build.Tasks.Windows.Run/Interop/ApplicationActivationManager.cs COM interop declarations for app activation manager + flags.
src/Controls/src/Build.Tasks.Windows.Run/Interop/PackageDebugSettings.cs COM interop declarations for terminating packaged app processes.

@mattleibow
mattleibow force-pushed the feature/dotnet-run-msix branch 3 times, most recently from 7399264 to 6b28008 Compare March 23, 2026 18:54
@mattleibow mattleibow changed the title Enable \dotnet run\ for MSIX-packaged MAUI Windows apps Enable dotnet run for MSIX-packaged MAUI Windows apps Mar 23, 2026
@mattleibow
mattleibow force-pushed the feature/dotnet-run-msix branch 3 times, most recently from c5f08d0 to 4db284e Compare March 23, 2026 19:09
@mattleibow
mattleibow requested a review from Copilot March 23, 2026 19:15
@mattleibow
mattleibow force-pushed the feature/dotnet-run-msix branch from 4db284e to f5f1228 Compare March 23, 2026 19:20

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.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

@mattleibow
mattleibow force-pushed the feature/dotnet-run-msix branch 2 times, most recently from f723d4b to b82eaa7 Compare March 23, 2026 19:31
@mattleibow
mattleibow requested a review from Copilot March 23, 2026 20:50

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.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Implements the DeployToDevice and ComputeRunArguments MSBuild extensibility
points from the dotnet-run-for-maui spec, enabling 'dotnet run' to work with
WindowsPackageType=MSIX apps that previously required Visual Studio.

New tool: Microsoft.Maui.Windows.Run (src/Controls/src/Build.Tasks.Windows.Run/)
- 'register' subcommand: registers MSIX package from loose layout via
  PackageManager.RegisterPackageAsync with DevelopmentMode
- 'run' subcommand: registers, computes AUMID, activates via
  IApplicationActivationManager COM, waits for exit, handles Ctrl+C

New MSBuild targets: Microsoft.Maui.Windows.Run.targets
- DeployToDevice: calls tool to register the MSIX package
- _WindowsMsixComputeRunArguments: sets RunCommand/RunArguments to launch
  the registered app via COM activation
- All targets conditioned on WindowsPackageType=MSIX (no impact on unpackaged)

Spec: https://github.com/dotnet/sdk/blob/main/documentation/specs/dotnet-run-for-maui.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattleibow
mattleibow force-pushed the feature/dotnet-run-msix branch from b82eaa7 to 89d6aef Compare March 23, 2026 21:05
mattleibow

This comment was marked as outdated.

@mattleibow
mattleibow marked this pull request as draft March 23, 2026 21:43
mattleibow added a commit that referenced this pull request Apr 19, 2026
…st infrastructure

- Create PromptBasedToolCallingClient: DelegatingChatClient that enables
  function calling for Phi Silica by injecting tool definitions into the
  system prompt and parsing <tool_call> JSON blocks from model output
- Fix PhiSilicaChatClient.ConvertToPrompt to handle FunctionCallContent
  and FunctionResultContent in multi-turn conversation history
- Add tool type validation (only AIFunction supported)
- Fix AI device test csproj: add DeviceTests.Runners.props import,
  SelfContained and WindowsAppSDKSelfContained for MSIX deployment
- Fix Run-DeviceTests.ps1: use _MauiDeviceTestUnpackaged instead of
  WindowsAppSDKSelfContained (prevents arch errors in dependencies)
- Fix windows.cake: add Essentials.AI.DeviceTests path mapping
- Cherry-pick dotnet run MSIX support from PR #34606

Results: 87/95 tests passing (22/27 function calling tests pass)

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

MauiBot commented May 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI Summary

👋 @mattleibow — new AI review results are available. Please review the latest session below.

📊 Review Session — 89d6aef · Enable dotnet run for MSIX-packaged MAUI Windows apps · 2026-05-03 07:01 UTC
🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ SKIPPED

No tests were detected in this PR.

Recommendation: Add tests to verify the fix using the write-tests-agent.


🧪 UI Tests — Category Detection

Full UI test matrix will run (no specific categories detected from PR changes).


🔍 Regression Cross-Reference

🔍 Regression Cross-Reference

🟢 No regression risks detected. No labeled bug-fix PRs in the last 6 months touched the modified files.


🔍 Pre-Flight — Context & Validation

Issue: No linked issue — standalone feature implementation
PR: #34606 - Enable dotnet run for MSIX-packaged MAUI Windows apps
Platforms Affected: Windows only (MSIX packaging path)
Files Changed: 7 implementation (new tool + targets), 0 test, 9 solution/project files, 2 sample config files

Key Findings

  • New standalone CLI tool Microsoft.Maui.Windows.Run added under src/Controls/src/Build.Tasks.Windows.Run/
  • Tool uses Windows Runtime (WinRT) PackageManager.RegisterPackageAsync with DevelopmentMode flag for loose-file MSIX registration
  • App activation via COM IApplicationActivationManager.ActivateApplication (same approach Visual Studio uses)
  • MSBuild targets implement DeployToDevice and ComputeRunArguments extensibility points from the dotnet-run-for-maui spec
  • All new MSBuild targets are properly conditioned on WindowsPackageType=MSIX — zero impact on unpackaged/sparse apps
  • Sample app's WindowsPackageType changed from None → MSIX and launchSettings.json updated to MsixPackage
  • Previous inline review comments (from prior Copilot review round) all resolved by author
  • Prior resolved issues addressed: stdout output removed from RunRegisterAsync, RuntimeIdentifier removed (now AnyCPU), IsDeveloperModeError + Environment.Exit(1) pattern, $(DOTNET_HOST_PATH) fallback, $(MSBuildThisFileDirectory) for tool path, EnableWindowsTargeting=true added
  • No automated tests added (Gate ⚠️ SKIPPED)
  • PR is in Draft state

Test Classification

  • Test type: No tests in PR
  • Gate result: ⚠️ SKIPPED — no tests detected

Impacted UI Test Categories

  • None — this is a build tooling / dotnet run infrastructure change, not a UI control change

Code Review Summary

Verdict: NEEDS_CHANGES
Confidence: high
Errors: 0 | Warnings: 2 | Suggestions: 2

Key code review findings:

  • ⚠️ eng/Microsoft.Maui.Packages.slnf:11 — Windows-only tool project included in pack filter used by macOS CI → active macOS Pack CI failure. Tool DLLs already staged by Controls.Build.Tasks.csproj; remove from Packages.slnf.
  • ⚠️ src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj:28 — Sample changed from WindowsPackageType=None to MSIX and launchSettings.json changed to MsixPackage. Likely test scaffolding; forces all contributors to need Developer Mode. Revert both files.
  • 💡 src/Controls/src/Build.Tasks.Windows.Run/AppActivator.cs:42 — Thread safety: cancellationToken.Register captures process which is null at registration time; race window between register and GetProcessById could leave app orphaned if packageFullName is also null.
  • 💡 src/Controls/src/Build.Tasks.Windows.Run/Controls.Build.Tasks.Windows.Run.csproj:13 — <AllowUnsafeBlocks>true</AllowUnsafeBlocks> set but no unsafe code exists. Remove.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #34606 New Microsoft.Maui.Windows.Run CLI tool + MSBuild targets enabling dotnet run for MSIX-packaged Windows apps ⏳ Gate SKIPPED 18 files New feature, draft PR

🔬 Code Review — Deep Analysis

Code Review — PR #34606

Independent Assessment

What this changes: This PR introduces a new standalone CLI tool (Microsoft.Maui.Windows.Run) and accompanying MSBuild targets that enable dotnet run to work with MSIX-packaged .NET MAUI Windows apps. Previously, running an MSIX app with dotnet run produced a REGDB_E_CLASSNOTREG COM exception because the app must be registered with the system's package manager before activation. The PR adds:

  1. A new src/Controls/src/Build.Tasks.Windows.Run/ project — a framework-dependent AnyCPU .NET console tool with register and run subcommands that wrap the PackageManager.RegisterPackageAsync and IApplicationActivationManager.ActivateApplication COM APIs.
  2. A new Microsoft.Maui.Windows.Run.targets file that implements the DeployToDevice and _WindowsMsixComputeRunArguments MSBuild extensibility points from the dotnet-run-for-maui spec.
  3. Wiring in Microsoft.Maui.Sdk.Windows.targets to import the new targets only for WindowsPackageType=MSIX.
  4. Changes to Controls.Build.Tasks.csproj to pack the tool DLLs alongside the existing targets.
  5. Registration of the new project in solution files and solution filters.
  6. A change to the Controls.Sample project switching it from unpackaged (None) to MSIX-packaged — and a matching launchSettings.json update.

Inferred motivation: dotnet run for MSIX apps requires a two-step process: (1) register the loose-file layout with the Windows package manager, and (2) activate the app via COM (not by running its EXE directly, which crashes). Visual Studio handles both steps internally. Without this, command-line MAUI development on MSIX projects requires VS. This PR closes that gap.


Reconciliation with PR Narrative

Author claims: Implements the dotnet-run-for-maui spec extensibility points (DeployToDevice, ComputeRunArguments) following the same pattern as Microsoft.Android.Run. The tool is framework-dependent AnyCPU to support both x64 and ARM64. All design decisions documented inline with comments.

Agreement/disagreement:

  • ✅ The architecture is sound and follows the documented spec and Android precedent.
  • ✅ COM interop GUIDs match the Windows API docs for IApplicationActivationManager and IPackageDebugSettings.
  • ✅ DOTNET_HOST_PATH fallback for dotnet host resolution is correct.
  • ✅ DtdProcessing.Prohibit in AppxManifestReader is correct XXE prevention.
  • ✅ DeploymentOptions.DevelopmentMode | ForceApplicationShutdown is the right flag combination for loose-file registration.
  • ⚠️ The sample project change (WindowsPackageType=MSIX) is not mentioned as intentional in the PR description — it appears to be test scaffolding that shouldn't merge.
  • ⚠️ The macOS Pack CI is actively failing, and the root cause appears to be the project's presence in Microsoft.Maui.Packages.slnf.

Findings

⚠️ Warning — macOS Pack CI failure: Microsoft.Maui.Packages.slnf includes Windows-only project

The new tool project is added to eng/Microsoft.Maui.Packages.slnf, which is consumed by the macOS Pack CI job (Pack .NET MAUI Pack macOS — currently failing). EnableWindowsTargeting=true allows the project to be loaded and restored on non-Windows but does not enable building it on macOS — the project references WinRT APIs (Windows.Management.Deployment) that cannot be compiled on macOS.

The tool DLLs are already staged into the NuGet package by Controls.Build.Tasks.csproj (lines 56–60, None items that pack the build output). The Windows.Run project itself does not need to be in the pack filter; only Controls.Build.Tasks.csproj does.

Fix: Remove "src\\Controls\\src\\Build.Tasks.Windows.Run\\Controls.Build.Tasks.Windows.Run.csproj" from eng/Microsoft.Maui.Packages.slnf.

⚠️ Warning — Sample project changed to MSIX; likely test scaffolding

src/Controls/samples/Controls.Sample/Maui.Controls.Sample.csproj was changed from WindowsPackageType=None (unpackaged) to WindowsPackageType=MSIX, and launchSettings.json changed from commandName: "Project" to commandName: "MsixPackage". This is not mentioned in the PR description as an intentional design decision.

The effects for all contributors using this sample:

  • Developer Mode must be enabled to run.
  • The F5/VS experience changes (requires MSIX tooling).
  • The Windows Release CI build failure may be related to this change (MSIX packaging requires additional CI configuration).

Fix: Revert both files to their pre-PR state. Use a separate test/sample or the developer's own project to validate the MSIX dotnet run workflow.

💡 Suggestion — Thread safety: process capture in cancellationToken.Register

AppActivator.cs lines 41–46:

Process? process = null;
cancellationToken.Register(() =>
{
    Console.WriteLine("Terminating app...");
    TryTerminatePackage(packageFullName, process);  // captures 'process' by variable reference
});
// ... later on same thread:
process = Process.GetProcessById((int)processId);

The Register callback captures process by closure reference. If cancellation fires in the window between Register() and process = Process.GetProcessById(...), the callback reads process == null. When packageFullName is also null (which GetPackageFullName can return silently on error), TryTerminatePackage does nothing — the just-launched app is left orphaned.

The catch (OperationCanceledException) at line 65 provides a second call to TryTerminatePackage, but it is only reached if WaitForExitAsync is entered — which it isn't if GetProcessById throws ArgumentException (early exit). The two paths don't fully cover each other.

The comment explains the intent ("Register BEFORE acquiring the process to avoid a race"), but the current approach trades one race for another. Consider using Interlocked.Exchange to write process with a full memory barrier, or restructure so the cancellation path always has access to packageFullName through a non-null variable when it matters most.

💡 Suggestion — AllowUnsafeBlocks=true with no unsafe code

Controls.Build.Tasks.Windows.Run.csproj line 13 sets <AllowUnsafeBlocks>true</AllowUnsafeBlocks>, but the project contains no unsafe blocks. COM interop via MarshalAs, ComImport, and IntPtr does not require this flag. Remove it to keep the project's compiler surface minimal.


Devil's Advocate

Challenging the warnings:

  • Packages.slnf CI failure: Could the macOS Pack job be failing for an unrelated pre-existing reason? Checked: the job is Pack .NET MAUI Pack macOS and this is a new failure introduced in this PR's run. The correlation with adding this project to the pack filter is direct. Confident this is the root cause.

  • Sample project change: Could the author intentionally want the sample to be MSIX? The PR description doesn't mention it, no issue references it, and the PR is a draft — this is almost certainly leftover test configuration. Keeping the warning.

Challenging the suggestions:

  • Thread safety in AppActivator: The scenario requires: (a) cancellation fires in a <1ms window, (b) packageFullName is null, (c) the app doesn't self-terminate. In practice this is extremely unlikely. However the existing comment explicitly calls out the race concern ("Register Ctrl+C handler BEFORE acquiring the process"), which acknowledges awareness of timing here — so a small code change to make it truly safe is warranted as a suggestion, not a blocker.

  • AllowUnsafeBlocks: This is definitely unnecessary. Low-risk to remove.

What could go wrong that I'm not seeing?

The DeployToDevice target + run subcommand double-registers the package (once in DeployToDevice, once inside run). Both use ForceApplicationShutdown. In the normal dotnet run flow this is harmless (registration is idempotent and fast), but if a developer has a long-running dev workflow where they do manual dotnet deploy + manual launch, the unexpected ForceApplicationShutdown during the second registration might terminate a running app. This is acceptable for a v1 and isn't a blocker.


Verdict: NEEDS_CHANGES

Confidence: high

Summary: The core architecture is solid and well-reasoned, closely following the Android precedent and the dotnet-run-for-maui spec. Two concrete issues must be addressed before merge: (1) the Windows-only project in Microsoft.Maui.Packages.slnf is causing an active macOS Pack CI failure and needs to be removed from that filter, and (2) the Controls.Sample project change to MSIX is almost certainly test scaffolding and should be reverted. The threading concern in AppActivator and the unnecessary AllowUnsafeBlocks are cleanup items that can be addressed in the same pass.


🔧 Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix (claude-opus-4.6) Apply code review warnings: remove tool from Packages.slnf, revert Controls.Sample, remove AllowUnsafeBlocks PASS 4 files Mandatory CI fixes
2 try-fix (claude-sonnet-4.6) Thread-safety restructure in AppActivator.cs: acquire Process before Register; dispose CancellationTokenRegistration; + warning fixes PASS 2 files Correctness + CI fixes
3 try-fix (gpt-5.3-codex) MSBuild manifest path: prefer $(AppxManifest) over hardcoded path; + warning fixes PASS 4 files Robustness + CI fixes
4 try-fix (gpt-5.5) PackageRegistrar: proactive registry Developer Mode check before RegisterPackageAsync; exception-based errors PASS 2 files Better UX + CI fixes
5 try-fix (claude-opus-4.6) Program.GetPackageFullName: FindPackagesFindPackagesForUser (non-admin safe) PASS 1 file Correctness fix
6 try-fix (gpt-5.5) PackageRegistrar: conditional ForceApplicationShutdown (false for 'register', true for 'run') PASS 2 files Behavioral correctness
PR PR #34606 New Microsoft.Maui.Windows.Run CLI tool + MSBuild targets Gate SKIPPED (draft) 18 files NEEDS_CHANGES per code review

Cross-Pollination

Model Round New Ideas? Details
claude-opus-4.6 2 Yes FindPackagesFindPackagesForUser attempt 5
claude-sonnet-4.6 2 Yes IPackageDebugSettings.EnableDebugging before launch (PLM prevention)
gpt-5.3-codex 2 Yes Launch fallback via explorer shell
gpt-5.5 2 Yes Conditional ForceApplicationShutdown attempt 6
claude-opus-4.6 3 Yes EnableDebugging/PLM (repeated)
gpt-5.5 3 Yes Pre-registration executable validation

Exhausted: Yes (3 cross-pollination rounds completed, max reached)
Selected Fix: pr-plus-reviewer The PR's core architecture is sound; code review warnings are the blocking issues. The pr-plus-reviewer candidate applies all reviewer feedback: removes tool from Packages.slnf (fixes macOS CI), reverts Controls.Sample, removes AllowUnsafeBlocks, and fixes AppActivator thread-safety. Try-fix 5 and 6 found additional real correctness improvements (FindPackagesForUser, conditional ForceApplicationShutdown) that should be incorporated by the author.


📋 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Draft PR, no linked issue, Windows tooling only, no prior agent reviews
Code Review NEEDS_CHANGES (high) 0 errors, 2 warnings, 2 suggestions
Gate ⚠️ SKIPPED No tests detected in this PR
Try-Fix ✅ COMPLETE 6 attempts, all 6 passing; 3 cross-pollination rounds exhausted
Report ✅ COMPLETE

Code Review Impact on Try-Fix

The code review's ⚠️ Warning findings directly shaped every try-fix attempt — all 6 candidates included the mandatory Packages.slnf and Controls.Sample fixes. The thread-safety 💡 Suggestion was addressed by try-fix-2 (AppActivator restructure). Beyond the code review findings, the cross-pollination rounds surfaced two additional correctness issues not in the original review: the FindPackages elevation bug (try-fix-5) and the unconditional ForceApplicationShutdown in register (try-fix-6). The MSBuild manifest path improvement (try-fix-3) and proactive Developer Mode check (try-fix-4) represent robustness improvements the author may want to consider.

Summary

PR #34606 is a well-architected new feature implementing the dotnet-run-for-maui spec for MSIX packaging. The design follows the Android precedent closely. However, two blocking ⚠️ Warning issues must be fixed before merge: (1) the Windows-only tool project was added to eng/Microsoft.Maui.Packages.slnf, directly causing macOS Pack CI failures; (2) Controls.Sample was changed from unpackaged to MSIX (test scaffolding that forces Developer Mode on all contributors). The try-fix phase additionally discovered that Program.GetPackageFullName uses FindPackages (requires admin elevation) instead of FindPackagesForUser, and that ForceApplicationShutdown is applied unconditionally even during pure registration — both real correctness issues worth fixing in the same pass.

Root Cause

The feature correctly solves the REGDB_E_CLASSNOTREG problem by implementing DeployToDevice (PackageManager registration) and ComputeRunArguments (COM activation via IApplicationActivationManager) as MSBuild extensibility points. The blocking issues are configuration/hygiene problems introduced during development: the Windows-only project ended up in a cross-platform pack filter, and the sample project's packaging mode was changed for local testing but not reverted.

Fix Quality

The PR's core feature implementation is high quality — proper WinRT API usage (DevelopmentMode | ForceApplicationShutdown), correct COM GUIDs, DtdProcessing.Prohibit for XXE safety, $(DOTNET_HOST_PATH) fallback, $(MSBuildThisFileDirectory) for tool path resolution. The two blocking issues are straightforward fixes. The pr-plus-reviewer candidate (applying all code review feedback) is the winning candidate: it preserves the feature implementation while addressing all blocking and advisory findings.

Winner: pr-plus-reviewer — Apply all code review feedback: remove tool from eng/Microsoft.Maui.Packages.slnf, revert Controls.Sample to WindowsPackageType=None, remove AllowUnsafeBlocks=true, and fix the AppActivator.cs thread-safety race. Additionally recommend incorporating the try-fix-5 (FindPackagesForUser) and try-fix-6 (ForceApplicationShutdown conditional) fixes as they address real correctness issues discovered during the multi-model exploration.


@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 4 findings

See inline comments for details.

@@ -10,6 +10,7 @@
"src\\Controls\\Foldable\\src\\Controls.Foldable.csproj",
"src\\Controls\\Maps\\src\\Controls.Maps.csproj",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[major] Build & MSBuild — This Windows-only tool project is included in Microsoft.Maui.Packages.slnf, which is consumed by the macOS Pack CI job. Even with EnableWindowsTargeting=true (which enables loading/restore, not building), the macOS agent cannot build a net10.0-windows10.0.19041.0 project that references WinRT APIs (Windows.Management.Deployment). This is the active root cause of the Pack .NET MAUI Pack macOS CI failure.

The tool DLLs are already staged into the NuGet package by Controls.Build.Tasks.csproj (via the None items in lines 56–60 of that file). The Windows.Run project does NOT need to be in the pack filter — only Controls.Build.Tasks.csproj does. Remove this project from Microsoft.Maui.Packages.slnf to fix the CI failure.

<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<WindowsPackageType>None</WindowsPackageType>
<WindowsPackageType>MSIX</WindowsPackageType>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[major] Build & MSBuild / Regression Prevention — The sample project's WindowsPackageType has been changed from None (unpackaged, runs directly) to MSIX (packaged, requires Windows Developer Mode and package registration).

This is almost certainly test scaffolding that should not merge:

  1. It forces all contributors using this sample to have Developer Mode enabled.
  2. Packaging slows the build and deploy cycle.
  3. The PR description doesn't list this as an intentional design decision.
  4. It also changes launchSettings.json commandName from Project to MsixPackage, breaking the standard VS F5 workflow for anyone without MSIX tooling configured.

Revert to <WindowsPackageType>None</WindowsPackageType> (and revert launchSettings.json) before merge. Use a separate sample or a test project to validate the MSIX workflow.

// Register Ctrl+C handler BEFORE acquiring the process to avoid a race
// where cancellation fires before the handler is set up.
Process? process = null;
cancellationToken.Register(() =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[moderate] Async and Threading — The cancellationToken.Register callback at line 42 captures the process variable. At registration time process is null; it is assigned on the calling thread at line 50. If cancellation fires in the narrow window between Register() and the process = Process.GetProcessById(...) assignment, two things happen:

  1. The registered callback fires with process == null.
  2. TryTerminatePackage(packageFullName, null) is called — if packageFullName is also null (returned from GetPackageFullName when FindPackages throws), the launched app is left running and orphaned.

The catch (OperationCanceledException) block at line 65 provides a secondary call to TryTerminatePackage, but it only runs if WaitForExitAsync is reached — which it isn't if cancellation fires before GetProcessById exits. Consider using a volatile field or Interlocked exchange to safely publish process, or restructure so the callback reads process through a captured Task<Process> that is already completed by the time WaitForExitAsync is entered.

<RootNamespace>Microsoft.Maui.Windows.Run</RootNamespace>
<AssemblyName>Microsoft.Maui.Windows.Run</AssemblyName>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[minor] Build & MSBuild — <AllowUnsafeBlocks>true</AllowUnsafeBlocks> is set but no unsafe blocks exist anywhere in this project. The COM interop (MarshalAs, ComImport, IntPtr) does not require AllowUnsafeBlocks. Remove this to keep the project's compiler surface minimal and avoid accidentally landing unsafe code in the future without a reviewable change.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates labels May 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants