Add muxer support for DOTNET_ROOT_REDIRECT_TARGET - #131983
Draft
JakeRadMSFT wants to merge 1 commit into
Draft
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in muxer redirect controlled by DOTNET_ROOT_REDIRECT_TARGET so dotnet can behave as if it were launched from a user-selected .NET hive (affecting hostfxr loading, SDK resolution, and framework resolution).
Changes:
- Introduces
DOTNET_ROOT_REDIRECT_TARGET_ENV_VARconstant in host utilities. - Updates muxer startup to use
DOTNET_ROOT_REDIRECT_TARGET(validated absolute path) as the effective dotnet root. - Adds
HostActivation.Testscoverage for SDK/framework resolution and “no fallback” behavior when the target hive is incomplete.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/native/corehost/hostmisc/utils.h | Adds the DOTNET_ROOT_REDIRECT_TARGET env var macro used by the muxer. |
| src/native/corehost/dotnet/dotnet.cpp | Applies the redirect at muxer startup by rebasing app_root before hostfxr + dotnet.dll resolution. |
| src/installer/tests/HostActivation.Tests/MuxerRedirect.cs | Adds tests validating redirect precedence and no-fallback behavior. |
Suppressed comments (2)
src/installer/tests/HostActivation.Tests/MuxerRedirect.cs:60
- This assertion includes the resolved framework base path, which is derived from the muxer-computed dotnet root and may be normalized differently than
_targetDotNet.BinPath(symlink resolution on Unix, long-path prefix on Windows). To keep the test stable while still proving redirection, assert the resolved framework name+version only.
.Execute()
.ShouldHaveResolvedFramework(Constants.MicrosoftNETCoreApp, TargetVersion, _targetDotNet.BinPath);
}
src/installer/tests/HostActivation.Tests/MuxerRedirect.cs:74
- Like the other tests in this file, this asserts the full redirect path string, but the muxer normalizes the path via
pal::fullpath, so the emitted trace may not contain the exactemptyTargetstring (symlink resolution / long-path prefix). Checking for the redirect trace prefix is enough here, since the primary assertion is that the command fails without listing the source SDK.
.Should().Fail()
.And.HaveStdErrContaining($"Redirecting dotnet root to [{emptyTarget}]")
.And.NotHaveStdOutContaining(SourceVersion);
Comment on lines
+46
to
+49
| .Should().Pass() | ||
| .And.HaveStdOutContaining($"{TargetVersion} [{Path.Combine(_targetDotNet.BinPath, "sdk")}") | ||
| .And.NotHaveStdOutContaining(SourceVersion) | ||
| .And.HaveStdErrContaining($"Redirecting dotnet root to [{_targetDotNet.BinPath}]"); |
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
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.
Summary
Add an opt-in muxer redirect that allows a user-selected .NET hive, such as the hive managed by
dotnetup, to replace the physical system hive for both SDK and runtime resolution.When
DOTNET_ROOT_REDIRECT_TARGETis set, thedotnetmuxer:hostfxrfrom the selected hivedotnet app.dllWhen the variable is not set, muxer behavior is unchanged.
User opt-in
This behavior is intentionally user opt-in. Setting
DOTNET_ROOT_REDIRECT_TARGETmeans: treat this path as my central .NET hive instead of the hive containing the muxer found onPATH.The system muxer may still be the executable found first on
PATH, but after startup it behaves as though the selected hive were in its place. The physical system hive is not used as a fallback by design; falling back would allow command-line tools, agents, and IDE tooling to silently select different SDKs again.dotnetupwill own the opt-in experience and clearly communicate this behavior when enabling it. Disabling the integration consists of removing the setting, which restores existing muxer behavior.Tooling experience
The broader goal is for command-line tools, agents, and C# Dev Kit to resolve the same current SDK from the user-managed hive.
Follow-up work outside this host change will:
dotnetupglobal.jsonfiles when appropriate, including using a roll-forward policy such aslatestFeatureso the latest compatible SDK in the managed hive can be selectedNormal
global.jsonversion, roll-forward, andsdk.pathsbehavior remains owned by the existing SDK resolver. This change relocates the muxer hive; it does not introduce a second SDK-selection policy.Validation
dotnet app.dllactivation resolves against the target hive--list-sdksand--list-runtimesreport the target hiveFocused
MuxerRedirecttests pass on macOS ARM64. The complete host suite requires the full CoreCLR product and pretest asset build, which was not available in the sparse prototype checkout.