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
19 changes: 1 addition & 18 deletions src/Aspire.Cli/DotNet/DotNetCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ internal sealed class DotNetCliRunner(
private const int MaxSearchRetries = 3;
private static readonly TimeSpan[] s_searchRetryDelays = [TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)];

private string GetMsBuildServerValue()
{
return configuration["DOTNET_CLI_USE_MSBUILD_SERVER"] ?? "true";
}

internal static string GetBackchannelSocketPath()
{
return CliPathHelper.CreateUnixDomainSocketPath("cli.sock");
Expand Down Expand Up @@ -520,12 +515,6 @@ public async Task<int> RunAsync(FileInfo projectFile, bool watch, bool noBuild,
// We copy the dictionary here because we don't want to mutate the input.
var finalEnv = env?.ToDictionary() ?? new Dictionary<string, string>();

// Inject DOTNET_CLI_USE_MSBUILD_SERVER when noBuild == false
if (!noBuild)
{
finalEnv["DOTNET_CLI_USE_MSBUILD_SERVER"] = GetMsBuildServerValue();
}

// Check if update notifications are disabled and set version check environment variable
if (!features.IsFeatureEnabled(KnownFeatures.UpdateNotificationsEnabled, defaultValue: true))
{
Expand Down Expand Up @@ -808,15 +797,9 @@ public async Task<int> BuildAsync(FileInfo projectFilePath, bool noRestore, Proc
string[] cliArgs = ["build", noRestoreSwitch, projectFilePath.FullName];
cliArgs = [.. cliArgs.Where(arg => !string.IsNullOrWhiteSpace(arg))];

// Always inject DOTNET_CLI_USE_MSBUILD_SERVER for apphost builds
var env = new Dictionary<string, string>
{
["DOTNET_CLI_USE_MSBUILD_SERVER"] = GetMsBuildServerValue()
};

return await ExecuteAsync(
args: cliArgs,
env: env,
env: null,
projectFile: projectFilePath,
workingDirectory: projectFilePath.Directory!,
backchannelCompletionSource: null,
Expand Down
21 changes: 8 additions & 13 deletions tests/Aspire.Cli.Tests/DotNet/DotNetCliRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task DotNetCliCorrectlyAppliesNoLaunchProfileArgumentWhenSpecifiedI
}

[Fact]
public async Task BuildAsyncAlwaysInjectsDotnetCliUseMsBuildServerEnvironmentVariable()
public async Task BuildAsyncDoesNotInjectDotnetCliUseMsBuildServerEnvironmentVariable()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var projectFile = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost.csproj"));
Expand All @@ -84,8 +84,7 @@ public async Task BuildAsyncAlwaysInjectsDotnetCliUseMsBuildServerEnvironmentVar
(args, env, _, _) =>
{
Assert.NotNull(env);
Assert.True(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
Assert.Equal("true", env["DOTNET_CLI_USE_MSBUILD_SERVER"]);
Assert.False(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
},
0);

Expand Down Expand Up @@ -123,14 +122,13 @@ public async Task RestoreAsyncRunsDotnetRestoreCommand()
}

[Fact]
public async Task BuildAsyncUsesConfigurationValueForDotnetCliUseMsBuildServer()
public async Task BuildAsyncDoesNotInjectConfiguredDotnetCliUseMsBuildServer()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var projectFile = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost.csproj"));
await File.WriteAllTextAsync(projectFile.FullName, "Not a real project file.");

var services = CliTestHelper.CreateServiceCollection(workspace, outputHelper);
// Add a configuration value that overrides the default
services.AddSingleton<IConfiguration>(sp =>
{
var configBuilder = new ConfigurationBuilder();
Expand All @@ -151,8 +149,7 @@ public async Task BuildAsyncUsesConfigurationValueForDotnetCliUseMsBuildServer()
(args, env, _, _) =>
{
Assert.NotNull(env);
Assert.True(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
Assert.Equal("false", env["DOTNET_CLI_USE_MSBUILD_SERVER"]);
Assert.False(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
},
0);

Expand Down Expand Up @@ -220,7 +217,7 @@ public async Task BuildAsyncDoesNotIncludeNoRestoreFlagWhenNoRestoreIsFalse()
}

[Fact]
public async Task RunAsyncInjectsDotnetCliUseMsBuildServerWhenNoBuildIsFalse()
public async Task RunAsyncDoesNotInjectDotnetCliUseMsBuildServerWhenNoBuildIsFalse()
{
using var workspace = TemporaryWorkspace.Create(outputHelper);
var projectFile = new FileInfo(Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost.csproj"));
Expand All @@ -238,15 +235,14 @@ public async Task RunAsyncInjectsDotnetCliUseMsBuildServerWhenNoBuildIsFalse()
(args, env, _, _) =>
{
Assert.NotNull(env);
Assert.True(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
Assert.Equal("true", env["DOTNET_CLI_USE_MSBUILD_SERVER"]);
Assert.False(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
},
0);

var exitCode = await runner.RunAsync(
projectFile: projectFile,
watch: false,
noBuild: false, // This should inject the environment variable
noBuild: false,
noRestore: false,
args: ["--operation", "inspect"],
env: new Dictionary<string, string>(),
Expand Down Expand Up @@ -317,8 +313,7 @@ public async Task RunAsyncPreservesExistingEnvironmentVariables()
(args, env, _, _) =>
{
Assert.NotNull(env);
Assert.True(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
Assert.Equal("true", env["DOTNET_CLI_USE_MSBUILD_SERVER"]);
Assert.False(env.ContainsKey("DOTNET_CLI_USE_MSBUILD_SERVER"));
// Verify existing environment variable is preserved
Assert.True(env.ContainsKey("EXISTING_VAR"));
Assert.Equal("existing_value", env["EXISTING_VAR"]);
Expand Down
Loading