Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ internal sealed class MSBuildForwardingAppWithoutLogging
private static readonly bool AlwaysExecuteMSBuildOutOfProc = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_RUN_MSBUILD_OUTOFPROC");

/// <summary>
/// An override flag that determines whether to use the MSBuild server - a persistent central node that can serve
/// A flag that determines whether to use the MSBuild server - a persistent central node that can serve
/// as a place to cache data and prevent re-doing CoreCLR startup/JITting for small builds.
/// By default, the MSBuild server is disabled due to stability/correctness concerns with some 1P tasks that keep static state around,
/// but it can be used by users that are confident they will not encounter those issues.
/// By default, the MSBuild server is enabled, but users that hit stability/correctness concerns with some
/// 1P tasks that keep static state around can opt out by setting this to false.
/// </summary>
private static readonly bool UseMSBuildServer = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_USE_MSBUILD_SERVER", false);
private static readonly bool UseMSBuildServer = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_USE_MSBUILD_SERVER", true);

/// <summary>
/// What the SDK's opinion is on the default terminal logger. The SDK defaults to '<c>auto</c>' which will use the terminal logger if the output is going to a terminal, otherwise it will use the console logger.
Expand Down Expand Up @@ -98,9 +98,10 @@ public MSBuildForwardingAppWithoutLogging(MSBuildArgs msbuildArgs, string? msbui

MSBuildPath = msbuildPath ?? defaultMSBuildPath;

// Only force MSBUILDUSESERVER on when DOTNET_CLI_USE_MSBUILD_SERVER opts in; otherwise leave
// any user-provided MSBUILDUSESERVER value untouched so it can toggle the server on its own.
if (UseMSBuildServer)
// The MSBuild server is enabled by default. Force MSBUILDUSESERVER on unless the user has opted out
// via DOTNET_CLI_USE_MSBUILD_SERVER, or has already set MSBUILDUSESERVER themselves - in which case we
// leave their value untouched so it can toggle the server on its own.
if (UseMSBuildServer && Env.GetEnvironmentVariable("MSBUILDUSESERVER") is null)
{
EnvironmentVariable("MSBUILDUSESERVER", "1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,21 @@ public void ItDoesNotSetCurrentWorkingDirectory()
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath)
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
}

[TestMethod]
public void ItEnablesMSBuildServerByDefault()
{
// The SDK enables the MSBuild server by default. Only assert this when the ambient environment
// hasn't already expressed an opinion via MSBUILDUSESERVER or DOTNET_CLI_USE_MSBUILD_SERVER.
if (Environment.GetEnvironmentVariable("MSBUILDUSESERVER") != null ||
Environment.GetEnvironmentVariable("DOTNET_CLI_USE_MSBUILD_SERVER") != null)
{
return;
}

var msbuildPath = "<msbuildpath>";
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath).GetProcessStartInfo();
startInfo.Environment["MSBUILDUSESERVER"].Should().Be("1");
}
}
}
Loading