Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: dotnet/android#10631

Add support for calling the DeployToDevice MSBuild target during dotnet run. The target is invoked after the build step (or with --no-build) to enable deployment to physical devices or emulators.

  • Create RunCommandSelector once per run for framework/device selection and deployment

  • Call DeployToDevice target if it exists in the project

  • Reuse cached ProjectInstance for performance

  • Add localized message for deployment failures

  • Added tests

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/DeployToDevice branch 2 times, most recently from b05d995 to 09f9f0d Compare December 9, 2025 20:15
jonathanpeppers added a commit to dotnet/android that referenced this pull request Dec 9, 2025
Context: dotnet/sdk#52046
Context: https://github.com/dotnet/sdk/blob/c164a9bc1246c48191fb780992530f0fe975141b/documentation/specs/dotnet-run-for-maui.md

When the `DeployToDevice` target is run by the `dotnet run` pipeline,
we will no longer need to make the `ComputeRunArguments` target deploy
anything.

We are thinking this feature can ship in future .NET 11 and 10.0.200
SDKs.
c164a9b is mostly working with two issues I've discovered while testing:

1. If `ComputeAvailableDevices` requires `Restore` to have run (which
   is actually the case for iOS and Android), `dotnet run` would fail
   unless you did an explicit `dotnet restore` first:

    D:\src\helloandroid> D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\dotnet.exe run -bl
      failed with 1 error(s) (0.1s)
      D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1004: Assets file 'D:\src\helloandroid\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

We can test this by changing `DotnetRunDevices.csproj`:

    <Target Name="ComputeAvailableDevices" DependsOnTargets="ResolveFrameworkReferences">

Doing an explicit `Restore` step before `ComputeAvailableDevices`
resolves this.

2. We were not passing loggers `ProjectInstance.Build()` calls in
   `RunCommandSelector`, so no logging output was shown during device
   computation. This is now fixed by creating a fresh console logger
   each time we call `Build()`.

I tested this manually with a console app with a
`ComputeAvailableDevices` target and a lengthy sleep:

    helloconsole                 ComputeAvailableDevices (9.1s)
Context: dotnet/android#10631

Add support for calling the `DeployToDevice` MSBuild target during
`dotnet run`. The target is invoked after the build step (or with
--no-build) to enable deployment to physical devices or emulators.

- Create `RunCommandSelector` once per run for framework/device
  selection and deployment

- Call `DeployToDevice` target if it exists in the project

- Reuse cached `ProjectInstance` for performance

- Add localized message for deployment failures

- Added tests
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.

2 participants