Skip to content

Have child processes use the same runtime as parent process #3104

@steveharter

Description

@steveharter

When a child framework-dependent apphost is launched today, it may not find the same framework that was used to launch it, or it may not find any framework at all.

To address this, a plan currently under review is to leverage the %DOTNET_ROOT% environment variable that was added in dotnet/core-setup#3888.

The additional detail below is preliminary pending design review:

This feature will set the environment variable for the current process, which will extend to child processes and be used to find the same runtime as the parent.

This environment variable at the global (or current environment) level is not set by our installers or by any (known) scripts. It is there for the user to set if the default install location does not work for framework-dependent apphost scenarios. However, this new feature sets the environment variable for the currently running dotnet.exe\apphost to allow child processes when launched to use the same runtime.

This helps replace current one-off implementations that may try one of several ways to find a runtime including the CLI's %DOTNET_HOST_PATH%, default install location, or the dotnet.exe found in %PATH%. Now when launching a dotnet.exe child process directly, the parent process can leverage DOTNET_ROOT. If launching a child apphost, the apphost will detect DOTNET_ROOT and look there for the runtime.

The current requirements:
• For dotnet.exe, DOTNET_ROOT is always set to the directory that contains the currently running dotnet.exe.
• For framework-dependent apphost.exe, DOTNET_ROOT is set to the location of the root of the parent dotnet directory that contains hostfxr.*
• For self-contained apphost.exe, DOTNET_ROOT is not set or used. A self-contained application does not need to find the runtime because it is local. The existing DOTNET_ROOT value is passed through.
• No multi-level lookup when DOTNET_ROOT is set. Multi-level lookup is a Windows feature where we pick the "most compatible" framework or SDK from %ProgramFiles% in addition to the current hive where dotnet.exe or apphost is running from, instead of just the current hive.

Note that for x86 applications running under Wow64, DOTNET_ROOT(x86) will be used instead. It is likely that both DOTNET_ROOT and DOTNET_ROOT(x86) will both be set in mixed 32- and 64-bit environments.

cc @jaredpar @richlander

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions