-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to make dotnet run
invoke an MSBuild target?
#31253
Comments
See also #18436. |
The options are either to do as suggested which would result in msbuild launching the process or we could run an additional target that returns the Command and Arguments that others could depend on to trigger their own targets. CC @rainersigwald for an opinion on having msbuild launching the process and what impact there might be. Hiding these behind a property makes sense to limit performance impact. Moving to 8.0.1xx for now as we've gotten more requests for this. |
No objection to having MSBuild invoke the thing directly (that's what's happening in the current implementation anyway, just through an additional process). |
Command & arguments seems a bit more extensible, in that the caller could run the command in a debugger or a syscall tracer, without needing each project to support those. Might need the ability for the project to specify environment variables for the process though. |
In the command & arguments implementation, if the developer wants to run some MSBuild targets rather than a built executable, then they can return "dotnet msbuild $(MSBuildProjectFullPath) -t:sometarget" as the command & arguments. Although it's not clear to me how the arguments should be quoted then; are the arguments are going to be just one string, or each argument as an item? |
This would really help both C#DK and MAUI in VS Code - simplifies quite a bit of the user experience if they choose to use CLI to build |
Additional use cases that came up during discussion with @danroth27 that we need to consider here:
In all of these cases running a particular project also requires starting/coordinating some number of other projects/processes. MSBuild doesn't have great support for this kind of lifecycle management (correct me if I'm wrong @rainersigwald), so spawning these kind of daemonized processes could be complex to orchestrate - you can't just So a full solution should cover:
Perhaps some kind of protocol is relevant here - the CLI could call some kind of target that would return MSBuild ITaskItems that described what processes to run, targets to run, etc, then the CLI could orchestrate
|
Alternatives here might be to go the route that Android-on-Rust has and make a separate .NET Tool that MAUI users might use that could do whatever orchestration you needed: |
Quick GitHub search query for folks that have overridden/actually used the Run target is here. I'm broadly seeing two categories:
|
One other thing to consider - VS/VSCode/CLI also use Launch Profiles to impact how the application is run. Anything we do here might impact them and we need to take that into account. |
Closing this as we implemented it in #42155! |
…target Context: dotnet/sdk#42155 Context: dotnet/sdk#42240 Fixes: dotnet/sdk#31253 The .NET SDK has introduced a new `ComputeRunArguments` MSBuild target that allows you to set `$(RunCommand)` and `$(RunArguments)` in a more dynamic way. So, on Android: * `ComputeRunArguments` depends on `Install`, so the app is deployed, the `<FastDeploy/>` MSBuild target runs, etc. * `$(RunCommand)` is a path to `adb` * `$(RunArguments)` is an `shell am start` command to launch the main activity. The new implementation also allows us to use the `-p` parameter with `dotnet run`, such as: dotnet run -bl -p:AdbTarget=-d This will pass `-d` to `adb`, which allows you to select an attached device if an emulator is running. Previously, we had no way to pass `-p` arguments to `dotnet run`.
Is your feature request related to a problem? Please describe.
In .NET 7, the ability to pass MSBuild properties was added to
dotnet run
.Unfortunately, this does not work for .NET MAUI projects, as we actually need an MSBuild target to run in order to deploy and launch an application on a mobile device.
To get an idea of our implementation currently:
https://github.com/xamarin/xamarin-android/blob/0e4c29aabb2af023d3ff66f02d42c2b487575d85/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets#L15-L16
We set
$(RunCommand)
and$(RunArguments)
to launch a new process that runsdotnet build -t:Run
. At this point we don't know what MSBuild properties were passed todotnet run
, so we don't have a way to pass them along.Describe the solution you'd like
If optional workloads could opt into a new setting like
$(UseTargetForRun)
(or choose a better name), it feels like the dotnet CLI should be able to invoke aRun
target directly instead of using$(RunCommand)
and$(RunArguments)
.This would allow the MSBuild properties to pass through, and we aren't starting an unnecessary
dotnet
process.Additional context
This is important for CLI scenarios for .NET MAUI.
The text was updated successfully, but these errors were encountered: