Skip to content

Commit b910144

Browse files
committed
Fix DOTNET_ROOT setting for dotnet run
1 parent 3121786 commit b910144

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Cli/dotnet/Commands/Run/RunCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static void SetRootVariableName(ICommand command, string runtimeIdentifier, stri
454454
runtimeIdentifier,
455455
defaultAppHostRuntimeIdentifier,
456456
targetFrameworkVersion);
457-
if (rootVariableName != null && Environment.GetEnvironmentVariable(rootVariableName) == null)
457+
if (rootVariableName != null && string.IsNullOrEmpty(Environment.GetEnvironmentVariable(rootVariableName)))
458458
{
459459
command.EnvironmentVariable(rootVariableName, Path.GetDirectoryName(new Muxer().MuxerPath));
460460
}

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,10 @@ public void Api_RunCommand()
30443044
string artifactsPath = OperatingSystem.IsWindows() ? @"C:\artifacts" : "/artifacts";
30453045
string executablePath = OperatingSystem.IsWindows() ? @"C:\artifacts\bin\debug\Program.exe" : "/artifacts/bin/debug/Program";
30463046
new DotnetCommand(Log, "run-api")
3047+
// The command outputs only _custom_ environment variables (not inherited ones),
3048+
// so make sure we don't pass DOTNET_ROOT_* so we can assert that it is set by the run command.
3049+
.WithEnvironmentVariable("DOTNET_ROOT", string.Empty)
3050+
.WithEnvironmentVariable($"DOTNET_ROOT_{RuntimeInformation.OSArchitecture.ToString().ToUpperInvariant()}", string.Empty)
30473051
.WithStandardInput($$"""
30483052
{"$type":"GetRunCommand","EntryPointFileFullPath":{{ToJson(programPath)}},"ArtifactsPath":{{ToJson(artifactsPath)}}}
30493053
""")

0 commit comments

Comments
 (0)