-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Write guidance on how to launch (non apphost) apps #88754
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsThere are scenarios where apps need to be launched with
I don't believe we've documented this. This question may be similar to how one locates
|
Depends where you want to do this. In a script something like |
This comes up frequently in the C# compiler source code as there are a number of cases where we need to launch a managed process. Effectively we have There are generally two scenarios I think about in this area:
After thinking this through this morning I think the right approach going forward is to only consult That would have the following impact on our product and testing:
|
If you're asking what is Perhaps I have the history / intent of this variable wrong and if so please correct me 😄 |
I think
This should spawn the child nodes for msbuild, csc and so on using the runtime/SDK from Unless we also change SDK to modify PATH for its child processes. Outside of SDK I agree that |
I 100% agree it uses it, I'm questioning why it does that. The
Why though? I'm struggling to see what value it provides vs. always using If we do want a variable that special cases the SDK though then
|
I realized this as well after I sent the response. It would be simpler if SDK just modified Unfortunately |
Yeah I'm not really thrilled about parsing Would be nice to have an API for @rainersigwald, @baronfel: have you all ever considered exposing a |
It's come up before but I couldn't find an issue so dotnet/msbuild#9018. |
This changes our `dotnet` launch code to not consider `$DOTNET_ROOT` as that is a apphost specific variable. After discussion with the runtime team determined that only `$PATH` will be considered for finding `dotnet`. dotnet/runtime#88754
@vitek-karas is there a managed API for finding the location of the muxer? Is this something we want to provide? |
No - we don't have an API like that. There's something similar in SDK: https://github.com/dotnet/sdk/blob/a4b77d4fd5e878fd42aef22d86c0668c90888da6/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs. And there seem to be other versions of this elsewhere, for example: https://github.com/microsoft/MSBuildLocator/blob/master/src/MSBuildLocator/DotNetSdkLocationHelper.cs (this one even mentions that maybe it should use nethost but doesn't). I know we've had several discussions with various SDK teams about this in the past, but no specific result. The problem is that there are like 5 versions of this code each with its own set of quirks and it's too late to change that. |
There is one other view to consider which was brought up in dotnet/roslyn#69023. Essentially all the tools that execute as part of an SDK action should use the same For example: > export PATH=/some/dotnet/install:$PATH
> which dotnet
/some/dotnet/install/dotnet
> /some/dotnet2/install/dotnet build In this view point tools like the compiler would be launched using I'm certainly sympathetic to this point of view. Mostly because the opposite view seems quite strange. Basically if I launch If there was an easy way from a process to find the |
This changes our `dotnet` launch code to not consider `$DOTNET_ROOT` as that is a apphost specific variable. After discussion with the runtime team determined that only `$PATH` will be considered for finding `dotnet`. dotnet/runtime#88754 Co-authored-by: Jared Parsons <jared@popcornbear.org>
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
… the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables
#18567) … the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables --------- Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
…OOT and DOTNET_HOST_PATH in. (#18591) . the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables Backport of #18567 --------- Co-authored-by: Mauro Agnoletti <mauro.agnoletti@gmail.com> Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
…T_PATH in. (#18590) . the Build Agent and remote tasks DOTNET_ROOT and DOTNET_HOST_PATH are being deprecated as a mechanism to store the location of dotnet. PATH will be used instead, so we should ensure that the existing code that makes usage of these variables is adapted to the new guidelines. More information: dotnet/roslyn@f454d69 dotnet/runtime#88754 (comment) Additionally, to avoid confusion, we are using a dedicate DOTNET_CUSTOM_PATH variable with the path of the dotnet used by the XMA Build Agent, so it can be used internally by the tasks without mixing it with the existing dotnet variables Backport of #18567 --------- Co-authored-by: Mauro Agnoletti <mauro.agnoletti@gmail.com> Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
I think an API called something like The problem being that there are a number of uncommon configurations where this will not work, including self-contained deployments where there just isn't a muxer to find. So this API would probably return @jaredpar Would this address all scenarios you're thinking of? I think the basic idea is that this would fix the problem, "I would like to start a new dotnet process using the same runtime/host that I'm running under." It wouldn't try to solve the problem of launching the "first" .NET process (either from native code or from the desktop framework). In those cases you would have to rely on PATH being appropriately configured, or use the native hosting APIs. Another limitation would be that the muxer serves double-duty as the entry point to both the runtime and to the SDK. There's no guarantee that an SDK will actually be present in any given dotnet process though. So people have to be careful to only use this to execute DLLs, not run SDK commands. |
I'm also not a fan of overriding PATH and looking into it, because it means that we can't use a dotnet exe without wrapping it with a batch/pwsh to setup this variable. That's really not great. Even if
Having an API would be nice, but I would think that making |
For me at least that is the primary problem to solve. Basically I have a suite of tools that launch each other and I want them to use the same host. |
This is a proven approach we've used in MsBuild and it functions well for this type of scenario. Perhaps this new API just seeds this value more automatically. |
@elinor-fung Any thoughts on the above? Either a managed API, or setting |
I don't really want to get the host itself into the business of setting environment variables. I think it would be reasonable to enable something like
Is it the same host that is desired, or the same runtime? Given dotnet/designs#303, those could be different locations. My impression is that the same runtime would be the desire. |
What about versions? Even if we provide API to get to the same runtime location, there might be several runtimes (and SDKs) installed there. Are the scenarios such that we would also want to be able to use the same version of the runtime/SDK as the currently running process? (I must admit I don't know exactly how we would do that, just asking what the scenario calls for). |
For build scenarios I think we want "same runtime and SDK as current MSBuild process"--at least for SDK built-in tooling like Roslyn. Tools packaged in NuGet packages may want more flexibility but that feels like a good default. |
On that topic, I have been having a difficult time to track down which process/main is actually setting |
By curiosity, how do we propagate from process to process the same runtime? (assuming we go through the |
I understand, and agree with, the reluctance for the runtime to be setting environment variables. At the same time though it would seem odd if the runtime is giving an API to find the host executable but then our SDK tool chain is effectively inventing another mechanism via
Agree it's the same runtime. Basically the location we can |
Actually, I don't think my statement was well-defined. What DOTNET_HOST_PATH is intended to do is point to a muxer that can run the target binary. There's no guarantee that binary will end up actually using the same runtime, due to all the decisions that happen when loading the binary (roll-forward, etc). I think my proposal is: find the muxer associated with the current hostfxr, if one exists. Run under that muxer. No guarantees about SDK or runtime. |
I think there are potentially two different scenarios here: do you want tools launched under your process to know that this is a .NET process and where it was launched from? Or do you simply want managed processes to be able to find a compatible muxer? I think of this as the divide between native children and managed children. If you want native children to know the location of the muxer, you probably want to use an environment variable. But also, I don't think this is an appropriate contract to use for the .NET runtime -- we wouldn't want to automatically pollute the environment variable space of child processes. Conversely, a managed API is effectively an entirely internal contract to a .NET binary. That's definitely the kind of thing that makes sense to build into every .NET app. So I think an AppContext switch makes a lot of sense as a universal host feature, and environment variable less so. But, I would also find it reasonable if the |
There are scenarios where apps need to be launched with
dotnet
host. The big question is how to find the host, with the two obvious places to look being:PATH
DOTNET_ROOT
,/etc/dotnet/install_location
, ...)I don't believe we've documented this.
This question may be similar to how one locates
node
from code given the use ofnvm
. I haven't looked at that pattern/guidance, but it seems similar.The text was updated successfully, but these errors were encountered: