Skip to content

Commit 2a788df

Browse files
authored
Configure DOTNET_ROOT when running apps (#16687)
The runtime uses DOTNET_ROOT to locate the .NET runtime. When unspecified, the CLI will continue to use the runtime from the global default. If you install dotnet to a location, configure the PATH, but not the runtime then you end up running in to issues where it complains about missing runtime.
1 parent 52beefa commit 2a788df

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Globalization;
8+
using System.IO;
89
using System.Threading;
910
using System.Threading.Tasks;
11+
using Microsoft.DotNet.Cli.Utils;
1012
using Microsoft.DotNet.Watcher.Internal;
1113
using Microsoft.DotNet.Watcher.Tools;
1214
using Microsoft.Extensions.Tools.Internal;
15+
using IReporter = Microsoft.Extensions.Tools.Internal.IReporter;
1316

1417
namespace Microsoft.DotNet.Watcher
1518
{
@@ -82,7 +85,10 @@ public async Task WatchAsync(DotNetWatchContext context, CancellationToken cance
8285
return;
8386
}
8487

85-
ConfigureExecutable(context, processSpec);
88+
if (context.Iteration == 0)
89+
{
90+
ConfigureExecutable(context, processSpec);
91+
}
8692

8793
using var currentRunCancellationSource = new CancellationTokenSource();
8894
var forceReload = _console.ListenForForceReloadRequest();
@@ -200,6 +206,12 @@ private static void ConfigureExecutable(DotNetWatchContext context, ProcessSpec
200206
processSpec.EnvironmentVariables["ASPNETCORE_URLS"] = context.DefaultLaunchSettingsProfile.ApplicationUrl;
201207
}
202208

209+
var rootVariableName = Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)";
210+
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(rootVariableName)))
211+
{
212+
processSpec.EnvironmentVariables[rootVariableName] = Path.GetDirectoryName(new Muxer().MuxerPath);
213+
}
214+
203215
if (context.DefaultLaunchSettingsProfile.EnvironmentVariables is IDictionary<string, string> envVariables)
204216
{
205217
foreach (var entry in context.DefaultLaunchSettingsProfile.EnvironmentVariables)

0 commit comments

Comments
 (0)