diff --git a/src/Workspaces/MSBuild/BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj b/src/Workspaces/MSBuild/BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj index 8a0b4c4c48559..8aa56fa294a70 100644 --- a/src/Workspaces/MSBuild/BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj +++ b/src/Workspaces/MSBuild/BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj @@ -43,7 +43,6 @@ - diff --git a/src/Workspaces/MSBuild/BuildHost/Program.cs b/src/Workspaces/MSBuild/BuildHost/Program.cs index ffe7588520874..d92ca7b5ea9cf 100644 --- a/src/Workspaces/MSBuild/BuildHost/Program.cs +++ b/src/Workspaces/MSBuild/BuildHost/Program.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Immutable; -using System.CommandLine; using System.Globalization; using System.IO.Pipes; using System.Threading.Tasks; @@ -13,28 +11,27 @@ namespace Microsoft.CodeAnalysis.MSBuild; internal static class Program { - internal static async Task Main(string[] args) + internal static async Task Main(string[] args) { // Note: we should limit the data passed through via command line strings, and pass information through IBuildHost.ConfigureGlobalState whenever possible. // This is because otherwise we might run into escaping issues, or command line length limits. - var pipeOption = new Option("--pipe") { Required = true }; - var localeOption = new Option("--locale") { Required = true }; - var command = new RootCommand { pipeOption, localeOption }; - var parsedArguments = command.Parse(args); - var pipeName = parsedArguments.GetValue(pipeOption)!; - var locale = parsedArguments.GetValue(localeOption)!; - var logger = new BuildHostLogger(Console.Error); + if (args is not [var pipeName, var cultureName]) + { + logger.LogCritical($"Expected arguments: "); + return -1; + } + try { - CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(locale); + CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(cultureName); } catch (CultureNotFoundException) { // We couldn't find the culture, log a warning and fallback to the OS configured value. - logger.LogWarning($"Culture {locale} was not found, falling back to OS culture"); + logger.LogWarning($"Culture '{cultureName}' was not found, falling back to OS culture"); } logger.LogInformation($"BuildHost Runtime Version: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}"); @@ -50,5 +47,7 @@ internal static async Task Main(string[] args) await server.RunAsync().ConfigureAwait(false); logger.LogInformation("RPC channel closed; process exiting."); + + return 0; } } diff --git a/src/Workspaces/MSBuild/Core/MSBuild/BuildHostProcessManager.cs b/src/Workspaces/MSBuild/Core/MSBuild/BuildHostProcessManager.cs index 3fee049f7d88d..8d1234c4f71c0 100644 --- a/src/Workspaces/MSBuild/Core/MSBuild/BuildHostProcessManager.cs +++ b/src/Workspaces/MSBuild/Core/MSBuild/BuildHostProcessManager.cs @@ -316,10 +316,7 @@ private static string GetBuildHostPath(string contentFolderName, string assembly private static void AppendBuildHostCommandLineArgumentsAndConfigureProcess(ProcessStartInfo processStartInfo, string pipeName) { - AddArgument(processStartInfo, "--pipe"); AddArgument(processStartInfo, pipeName); - - AddArgument(processStartInfo, "--locale"); AddArgument(processStartInfo, System.Globalization.CultureInfo.CurrentUICulture.Name); // MSBUILD_EXE_PATH is read by MSBuild to find related tasks and targets. We don't want this to be inherited by our build process, or otherwise diff --git a/src/Workspaces/MSBuild/Test/BuildHostProcessManagerTests.cs b/src/Workspaces/MSBuild/Test/BuildHostProcessManagerTests.cs index a3d0a1de06c09..4b3b2604b5502 100644 --- a/src/Workspaces/MSBuild/Test/BuildHostProcessManagerTests.cs +++ b/src/Workspaces/MSBuild/Test/BuildHostProcessManagerTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.Immutable; +using System.Linq; using Moq; using Roslyn.Test.Utilities; using Xunit; @@ -63,14 +64,15 @@ internal void ProcessStartInfo_PassesPipeName(BuildHostProcessKind buildHostKind const string PipeName = "TestPipe"; var processStartInfo = BuildHostProcessManager.CreateBuildHostStartInfo(buildHostKind, PipeName, dotnetPath: null); - #if NET - var binlogIndex = processStartInfo.ArgumentList.IndexOf("--pipe"); - Assert.True(binlogIndex >= 0); - Assert.Equal(PipeName, processStartInfo.ArgumentList[binlogIndex + 1]); + var args = processStartInfo.ArgumentList; #else - Assert.Contains($"--pipe {PipeName}", processStartInfo.Arguments); + var args = processStartInfo.Arguments.Split(' '); #endif + Assert.True(args.Count() >= 2, $"Expected at least 2 args: '{string.Join(",", args)}'"); + + Assert.Equal(PipeName, args[^2]); + Assert.Equal(System.Globalization.CultureInfo.CurrentUICulture.Name, args[^1]); } [Theory] @@ -80,16 +82,17 @@ internal void ProcessStartInfo_PassesPipeName(BuildHostProcessKind buildHostKind [UseCulture("de-DE", "de-DE")] internal void ProcessStartInfo_PassesLocale(BuildHostProcessKind buildHostKind) { - const string Locale = "de-DE"; - - var processStartInfo = BuildHostProcessManager.CreateBuildHostStartInfo(buildHostKind, pipeName: "", dotnetPath: null); + const string PipeName = "TestPipe"; + var processStartInfo = BuildHostProcessManager.CreateBuildHostStartInfo(buildHostKind, PipeName, dotnetPath: null); #if NET - var localeIndex = processStartInfo.ArgumentList.IndexOf("--locale"); - Assert.True(localeIndex >= 0); - Assert.Equal(Locale, processStartInfo.ArgumentList[localeIndex + 1]); + var args = processStartInfo.ArgumentList; #else - Assert.Contains($"--locale {Locale}", processStartInfo.Arguments); + var args = processStartInfo.Arguments.Split(' '); #endif + Assert.True(args.Count() >= 2, $"Expected at least 2 args: '{string.Join(",", args)}'"); + + Assert.Equal(PipeName, args[^2]); + Assert.Equal("de-DE", args[^1]); } }