Skip to content

Commit

Permalink
Dont look for vslang because vs can manage the lang settings itself a…
Browse files Browse the repository at this point in the history
…lready and also fix a test to use en because bild machines are apparently in french sometimes???
  • Loading branch information
nagilson committed Mar 13, 2023
1 parent 9b1c074 commit 5a06292
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ public void TestEnvironmentTest()
[Fact]
public void MSBuildEngineLogger()
{
using TestEnvironment testEnvironment = TestEnvironment.Create();
testEnvironment.SetEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en"); // build machines may have other values.

string oldValueForMSBuildLoadMicrosoftTargetsReadOnly = Environment.GetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly");
string projectString =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
Expand Down
24 changes: 7 additions & 17 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,13 +1678,15 @@ internal static void SetConsoleUI()
}

/// <summary>
/// The .NET SDK and Visual Studio both have environment variables that set a custom language. MSBuild should respect those variables.
/// The .NET SDK and Visual Studio both have environment variables that set a custom language. MSBuild should respect the SDK variable.
/// To use the correspoding UI culture, in certain cases the console encoding must be changed. This function will change the encoding in these cases.
/// This code introduces a breaking change due to the encoding of the console being changed.
/// If the environment variables are undefined, this function should be a no-op.
/// </summary>
/// <returns>The custom language that was set by the user for an 'external' tool besides MSBuild.
/// DOTNET_CLI_UI_LANGUAGE > VSLANG. Returns <see langword="null"/> if none are set.</returns>
/// <returns>
/// The custom language that was set by the user for an 'external' tool besides MSBuild.
/// Returns <see langword="null"/> if none are set.
/// </returns>
private static CultureInfo GetExternalOverridenUILanguageIfSupportableWithEncoding()
{
CultureInfo externalLanguageSetting = GetExternalOverriddenUILanguage();
Expand Down Expand Up @@ -1736,12 +1738,12 @@ private static bool ForceUniversalEncodingOptInEnabled()
}

/// <summary>
/// Look at UI language overrides that can be set by known external invokers. (DOTNET_CLI_UI_LANGUAGE and VSLANG).
/// Look at UI language overrides that can be set by known external invokers. (DOTNET_CLI_UI_LANGUAGE.)
/// Does NOT check System Locale or OS Display Language.
/// Ported from the .NET SDK: https://github.com/dotnet/sdk/blob/bcea1face15458814b8e53e8785b52ba464f6538/src/Cli/Microsoft.DotNet.Cli.Utils/UILanguageOverride.cs
/// </summary>
/// <returns>The custom language that was set by the user for an 'external' tool besides MSBuild.
/// DOTNET_CLI_UI_LANGUAGE > VSLANG. Returns null if none are set.</returns>
/// Returns null if none are set.</returns>
private static CultureInfo GetExternalOverriddenUILanguage()
{
// DOTNET_CLI_UI_LANGUAGE=<culture name> is the main way for users to customize the CLI's UI language via the .NET SDK.
Expand All @@ -1755,18 +1757,6 @@ private static CultureInfo GetExternalOverriddenUILanguage()
catch (CultureNotFoundException) { }
}

// VSLANG=<lcid> is set by Visual Studio.
string vsLang = Environment.GetEnvironmentVariable("VSLANG");
if (vsLang != null && int.TryParse(vsLang, out int vsLcid))
{
try
{
return new CultureInfo(vsLcid);
}
catch (ArgumentOutOfRangeException) { }
catch (CultureNotFoundException) { }
}

return null;
}

Expand Down

0 comments on commit 5a06292

Please sign in to comment.