Skip to content

[release/11.0.1xx] [dotnet] Add DeployToDevice MSBuild target for 'dotnet run' support - #26830

Open
rolfbjarne wants to merge 18 commits into
release/11.0.1xxfrom
dev/rolf/backport-pr-25977-release/11.0.1xx-2026-10-02
Open

rolfbjarne wants to merge 18 commits into
release/11.0.1xxfrom
dev/rolf/backport-pr-25977-release/11.0.1xx-2026-10-02

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Implement the DeployToDevice target as specified in the dotnet run for MAUI spec. This target deploys an already-built app to a device or simulator without rebuilding, enabling the dotnet run --no-build workflow.

The target:

  • Reuses existing GetMlaunchArguments task to compute install arguments
  • Supports both physical devices (--installdev) and simulators (--installsim)
  • Accepts the $(Device) property for device selection
  • Depends on ComputeAvailableDevices for device discovery
  • Only applies to mobile platforms (iOS/tvOS) via SdkIsMobile condition

Fixes #24382

🤖 Pull request created by Copilot


Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com
Co-authored-by: Rolf Bjarne Kvinge rokvin@microsoft.com

Backport of #25977.

rolfbjarne and others added 18 commits October 2, 2026 18:58
Implement the DeployToDevice target as specified in the dotnet run for
MAUI spec. This target deploys an already-built app to a device or
simulator without rebuilding, enabling the 'dotnet run --no-build'
workflow.

The target:
- Reuses existing GetMlaunchArguments task to compute install arguments
- Supports both physical devices (--installdev) and simulators (--installsim)
- Accepts the $(Device) property for device selection
- Depends on ComputeAvailableDevices for device discovery
- Only applies to mobile platforms (iOS/tvOS) via SdkIsMobile condition

Fixes #24382

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover both a device RID and a simulator RID, asserting the computed
mlaunch install arguments (--installdev vs --installsim), and add a
test asserting a clear error is raised when the app hasn't been built.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Clean the test project's RID-specific outputs before building so stale ready-to-run state from earlier test cases cannot cause missing assembly failures. Also treat an empty MlaunchInstallArguments property as unavailable, allowing the expected no-device error path on CI agents without attached devices.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Run the Clean target through dotnet build so the selected runtime identifier is restored before cleanup. A direct dotnet clean fails when the shared test project's existing assets file was generated for another RID.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Exercise both physical-device and simulator installation arguments for tvOS, matching the platform coverage of the DeployToDevice target.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Run hot reload configuration validation before DeployToDevice installs the app, while retaining the post-deployment startup-hook copy step. Document the public DeployToDevice target, its Device selection property, and its use by dotnet run --no-build.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Add a deterministic physical-device case that confirms the Device property is forwarded to mlaunch as --devname. Revert the unrelated macOS CoreCLR app-size baseline update because the deploy target is mobile-only.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Use a deterministic mlaunch stub for explicit device selection and assert that DeployToDevice executes it with the computed installation arguments. This keeps the no-device tolerance while ensuring removal of the deployment Exec task is detected.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Restore the public GetMlaunchArguments.Help parameter and ShowRunHelp target so existing MSBuild integrations continue to work. Keep the compatibility path conditioned away from normal deployment and run argument computation.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Restore the discarded-device help test alongside the compatibility implementation so changes to the public Help path continue to be validated.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Restrict the executable mlaunch test stub to non-Windows hosts so the cross-platform test assembly satisfies CA1416 while retaining deterministic deployment execution coverage on macOS CI agents.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Prevent parameterized DeployToDevice cases from cleaning and building the same referenced project directories concurrently, which caused intermittent MSB3231 failures in CI.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Inspect the deployment binlog and assert that Build, Compile, and CoreCompile are not executed. This protects DeployToDevice's no-build contract from future dependency regressions.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Override the mobile Run target so direct MSBuild invocations deploy before computing launch arguments. The .NET SDK's deploy-then-compute orchestration remains separate and therefore does not deploy twice.

Add a stub-backed regression test that verifies direct Run performs exactly one install followed by one launch.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Keep DeployToDevice and ComputeRunArguments dependencies on the later Windows Run override while retaining remote Exec session handling.

Allow an explicitly selected device to proceed when discovery returns no devices, and cover the behavior at the task level. This makes direct Run regression coverage deterministic without requiring connected hardware.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Prevent deployment tests from cleaning shared referenced-project outputs while preserving RID-specific cleanup for the app under test. This avoids races with other fixtures building MonoTouch.Dialog concurrently.

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

Copilot-Session: d07a98d3-3b68-4bfa-8c58-a4e0f8f87d7a
Copilot AI balanced review requested due to automatic review settings October 2, 2026 17:13
@rolfbjarne rolfbjarne added backported ready-to-review This PR is ready to review/merge. labels Oct 2, 2026

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.

Copilot review overview

🟡 Changes recommended

The target changes break physical-device hot reload, allow manifest compilation during no-build deployment, and invoke mlaunch during simulator help requests.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
What changed in this PR

Backports deployment-only support to .NET 11 Apple tooling, enabling dotnet run --no-build for iOS and tvOS.

Changes:

  • Adds device and simulator deployment and connects it to Run.
  • Allows explicit device selection without discovery results.
  • Documents the target and adds deployment regression tests.
File Description
tests/​msbuild/​Xamarin.MacDev.Tasks.Tests/​TaskTests/​GetMlaunchArgumentsTaskTests.cs Tests explicit device selection.
tests/​dotnet/​UnitTests/​MlaunchTest.cs Tests deployment, missing bundles, and install-before-launch ordering.
msbuild/​Xamarin.MacDev.Tasks/​Tasks/​GetMlaunchArguments.cs Allows explicit devices without discovery results.
msbuild/​Xamarin.iOS.Tasks.Windows/​Xamarin.iOS.Common.After.targets Adds deployment and argument preparation before remote execution.
dotnet/​targets/​Microsoft.Sdk.Mobile.targets Adds deployment targets and updates launch dependencies.
docs/​building-apps/​build-targets.md Documents DeployToDevice.

Comment thread dotnet/targets/Microsoft.Sdk.Mobile.targets
Name="_PrepareRunMobile"
BeforeTargets="ComputeRunArguments"
DependsOnTargets="_ValidateHotReloadConfiguration;_InstallMobile;_CopyStartupHooksToDevice;ComputeMlaunchRunArguments"
DependsOnTargets="_ValidateHotReloadConfiguration;ComputeMlaunchRunArguments"
Comment thread dotnet/targets/Microsoft.Sdk.Mobile.targets
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 9891a344982fa33c3210122335b97051c1bfdbc9 [PR build]

@rolfbjarne rolfbjarne added the do-not-merge Do not merge this pull request label Oct 2, 2026
@rolfbjarne

Copy link
Copy Markdown
Member Author

Copilot might be right that this breaks hot reload on device, some more testing is needed.

@rolfbjarne rolfbjarne removed the ready-to-review This PR is ready to review/merge. label Oct 2, 2026
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #9891a34] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 1 tests failed, 265 tests passed.

Failures

❌ dotnettests tests (tvOS)

1 tests failed, 0 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)
    • Xamarin.Tests.DotNetProjectTest.PublishAotMonoTouchTest_NoIL2009...: Unexpected warning: builds/downloads/dotnet-sdk-11.0.100-rc.2.26465.108/sdk/11.0.100-rc.2.26465.108/Microsoft.Common.CurrentVers...

Html Report (VSDrops) Download

❌ windows tests

🔥 Failed catastrophically on VSTS: test results - windows (no summary found).

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 9891a344982fa33c3210122335b97051c1bfdbc9 [PR build]

This branch has not been deployed

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

Labels

backported do-not-merge Do not merge this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants