Skip to content
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

There doesn't seem to be a way to execute tasks or targets for 'dotnet run' #18436

Closed
rolfbjarne opened this issue Jun 22, 2021 · 4 comments
Closed

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented Jun 22, 2021

Description

For mobile platforms (iOS, tvOS), we need to execute tasks to figure out a few things before we can run an app.

So we implemented a target to run before the Run target:

https:/xamarin/xamarin-macios/blob/6ce5f80cb7ef96000652fdd534c9176b793402e9/dotnet/targets/Xamarin.Shared.Sdk.targets#L859

This works fine for dotnet build -t:Run, but it doesn't not work for dotnet run, because from what I can see dotnet run will pick out the RunCommand and RunArguments properties once the project has been evaluated:

var project = new ProjectInstance(Project, globalProperties, null);
string runProgram = project.GetPropertyValue("RunCommand");
if (string.IsNullOrEmpty(runProgram))
{
ThrowUnableToRunError(project);
}
string runArguments = project.GetPropertyValue("RunArguments");
string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory");
if (Args.Any())
{
runArguments += " " + ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(Args);
}
CommandSpec commandSpec = new CommandSpec(runProgram, runArguments);
var command = CommandFactoryUsingResolver.Create(commandSpec)
.WorkingDirectory(runWorkingDirectory);
var rootVariableName = Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)";
if (Environment.GetEnvironmentVariable(rootVariableName) == null)
{
command.EnvironmentVariable(rootVariableName, Path.GetDirectoryName(new Muxer().MuxerPath));
}
return command;

instead of executing the Run target, which means that the RunCommand and RunArguments properties aren't set, because we set them inside a target:

https:/xamarin/xamarin-macios/blob/6ce5f80cb7ef96000652fdd534c9176b793402e9/dotnet/targets/Xamarin.Shared.Sdk.targets#L846-L849

The end result is that with an iOS app executing dotnet run just doesn't work:

  • Install .NET 6 Preview 6 on a Mac.
  • Install the iOS workload: sudo dotnet workload install microsoft-ios-sdk-full
  • Clone https:/dotnet/maui-samples (hash: bb264d046139f6635ed066157c44b99010b8d1dd)
  • Build & run HelloiOS
$ cd HelloiOS
$ dotnet build
$ dotnet run --no-build
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '/Users/rolf/work/net6-mobile-samples/HelloiOS/bin/Debug/net6.0-ios/iossimulator-x64/'.
Failed to run as a self-contained app.
  - The application was run as a self-contained app because '/Users/rolf/work/net6-mobile-samples/HelloiOS/bin/Debug/net6.0-ios/iossimulator-x64/HelloiOS.runtimeconfig.json' did not specify a framework.
  - If this should be a framework-dependent app, specify the appropriate framework in '/Users/rolf/work/net6-mobile-samples/HelloiOS/bin/Debug/net6.0-ios/iossimulator-x64/HelloiOS.runtimeconfig.json'
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jun 22, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dsplaisted dsplaisted added the needs team triage Requires a full team discussion label Jul 29, 2021
@dsplaisted dsplaisted removed their assignment Jul 29, 2021
@dsplaisted dsplaisted removed the untriaged Request triage from a team member label Jul 29, 2021
@marcpopMSFT marcpopMSFT added this to the Backlog milestone Aug 4, 2021
@marcpopMSFT marcpopMSFT added Area-CLI Area-NetSDK and removed needs team triage Requires a full team discussion labels Aug 4, 2021
@marcpopMSFT
Copy link
Member

This is a reasonable request but deferring to investigations around multi-project startup. @KathleenDollard

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Aug 17, 2021
…'dotnet run'.

.NET doesn't support executing other targets/tasks when doing "dotnet run".
However, we need to (like we do for our current "Run" target), so implement a
rather simplistic/hacky workaround by making "dotnet run" just do "dotnet
build /t:Run".

It doesn't support everything that "dotnet run" does (for instance it doesn't
support the /no-build flag), but it should work for most use cases.

Ref: dotnet/sdk#18436
rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Aug 17, 2021
…'dotnet run'. (#12458)

.NET doesn't support executing other targets/tasks when doing "dotnet run".
However, we need to (like we do for our current "Run" target), so implement a
rather simplistic/hacky workaround by making "dotnet run" just do "dotnet
build /t:Run".

It doesn't support everything that "dotnet run" does (for instance it doesn't
support the /no-build flag), but it should work for most use cases.

Ref: dotnet/sdk#18436
@rolfbjarne
Copy link
Member Author

Any updates on this?

@baronfel
Copy link
Member

baronfel commented Sep 28, 2023

Going to close this one as a duplicate of #31253, even though this one is older, since #31253 has more discussion on it.

@baronfel baronfel closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants