-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[dotnet-run] Implement DeployToDevice target invocation
#52046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jonathanpeppers
wants to merge
1
commit into
main
Choose a base branch
from
dev/peppers/DeployToDevice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 tasks
b05d995 to
09f9f0d
Compare
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.
023e459 to
cb6877a
Compare
Context: dotnet/android#10631 Context: dotnet/android#10640 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. The main change here is to create the `RunCommandSelector` earlier in the `RunCommand` execution, so that it can be used both for selecting the target framework and device before build, and for invoking the `DeployToDevice` target after build. I tested this by making `DotnetRunDevices.csproj` include a target: <Target Name="DeployToDevice" DependsOnTargets="ResolveFrameworkReferences"> <Message Text="DeployToDevice: Deployed to device $(Device) with RuntimeIdentifier $(RuntimeIdentifier)" Importance="high" /> </Target> Where `DependsOnTargets="ResolveFrameworkReferences"` mimics what can happen in the Android workload. I had to stop caching each `ProjectInstance` in `RunCommandSelector`, as doing so can cause: 》"artifacts\tmp\Debug\testing\ItDoesNotCall---A078BA19\DotnetRunDevices.csproj" (DeployToDevice target) (1) -> 》(ResolveFrameworkReferences target) -> 》 artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: The "ResolveFrameworkReferences" task failed unexpectedly. 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: System.ArgumentException: An item with the same key has already been added. Key: Microsoft.NETCore.App 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at System.Linq.Enumerable.SpanToDictionary[TSource,TKey](ReadOnlySpan`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolveFrameworkReferences.ExecuteCore() in src\Tasks\Microsoft.NET.Build.Tasks\ResolveFrameworkReferences.cs:line 29 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() in src\Tasks\Common\TaskBase.cs:line 36 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() 》artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(410,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) The `ResolveFrameworkReferences` target will add duplicate `Microsoft.NETCore.App` items within a `ProjectInstance` causing the exception above.
cb6877a to
3933774
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: https://github.com/dotnet/sdk/blob/49c0d73c0bfa9eb2870827828354d5c96ed786f0/documentation/specs/dotnet-run-for-maui.md
Context: dotnet/android#10631
Context: dotnet/android#10640
Add support for calling the
DeployToDeviceMSBuild target duringdotnet run. The target is invoked after the build step (or with --no-build) to enable deployment to physical devices or emulators.The main change here is to create the
RunCommandSelectorearlier in theRunCommandexecution, so that it can be used both for selecting the target framework and device before build, and for invoking theDeployToDevicetarget after build.I tested this by making
DotnetRunDevices.csprojinclude a target:Where
DependsOnTargets="ResolveFrameworkReferences"mimics what can happen in the Android workload.I had to stop caching each
ProjectInstanceinRunCommandSelector,as doing so can cause:
The
ResolveFrameworkReferencestarget will add duplicateMicrosoft.NETCore.Appitems within aProjectInstancecausing the exception above.