msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

MSBuild should respect upstream tool language requests

Open cdmihai opened this issue 8 years ago • 10 comments

Different upstream tools have different language configuration requirements:

  • dotnet CLI sets DOTNET_CLI_UI_LANGUAGE and VSLANG (https://github.com/Microsoft/msbuild/issues/1596#issuecomment-409362785 https://github.com/dotnet/cli/issues/9722#issuecomment-409358296)
  • Visual Studio has a fallback mechanism guideline. In order:
    • VSLANG environmnent variable
    • /lcid command line switch
    • call GetConsoleFallbackUICulture (we only do this currently)

Related info: https://github.com/dotnet/cli/issues/4988#issuecomment-266836559

cdmihai avatar Jan 21 '17 00:01 cdmihai

VSLANG is sufficient for CLI and VS since we set that when the language is overridden by means other than VSLANG.

nguerrera avatar Jul 31 '18 20:07 nguerrera

Is there a workaround while this is still in development? I've tried:

set DOTNET_CLI_UI_LANGUAGE=en

and also:

set VSLANG=1033

to try to get the msbuild output to switch to English when using the dotnet build command, but neither works.

martinstein avatar May 20 '19 16:05 martinstein

Only option I know is to change the machine's language.

cdmihai avatar May 20 '19 18:05 cdmihai

It might be interesting for msbuild to do what CLI does and re-export other things like PreferredUILanguage. This would give the same compiler localization as dotnet build if you configure an env var.

nguerrera avatar Aug 09 '19 22:08 nguerrera

The BuildParameters class has culture and uiculture fields. I don’t see the ability to set these parameters through the command line parameters (dotnet build | dotnet pack). In my case, I use the CI / CD service (gocd), artifact files has invalid the wrong encoding, it is not clear how to set the encoding.

lobster2012-user avatar Jan 05 '20 23:01 lobster2012-user

chcp 437 seems to work if you call it before invoking MSBuild

KirillOsenkov avatar Jun 16 '20 18:06 KirillOsenkov

This would be incredibly useful when reporting problems; I do use non-English UI language, but it'd be very useful if the output language could be specified by environment variable or something because others do not understand it.

I'm not exactly sure if this is a MSBuild part or somewhere else, but for example, when I type dotnet new -i Microsoft.PowerShell.Standard.Module.Template, there's a first few messages that are printed in local language (in my case, Korean) saying "determining projects to restore". I've tried setting chcp 437, $env:DOTNET_CLI_UI_LANGUAGE = "en-us" and $env:VSLANG=1033 but none of them seem to work.

Gnbrkm41 avatar Aug 02 '20 12:08 Gnbrkm41

@Gnbrkm41 I've filed https://github.com/dotnet/sdk/issues/12747 on your behalf. Since it's dotnet.exe it should probably go there.

For now, chcp 437 from the command line should work for MSBuild.exe.

KirillOsenkov avatar Aug 03 '20 17:08 KirillOsenkov

Deleting C:\Program Files\dotnet\sdk\{sdk-version}\{locale} folder can also be used as a workaround.

shadow-cs avatar Dec 04 '20 11:12 shadow-cs

It has been over 5 years since the issue opened. Is it resolved? I still cannot change the MSBuild locale without changing OS locale. Tried chcp 437, $env:DOTNET_CLI_UI_LANGUAGE = "en-US" and $env:VSLANG="1033".

hcoona avatar Sep 15 '22 13:09 hcoona

I think we can solve this issue by geting UILanguageOverride into MSBuild to support overriding its output language:

https://github.com/dotnet/sdk/blob/49d9b4148c4f65fd3f691186a4533375c3a83c97/src/Cli/dotnet/UILanguageOverride.cs#L9

dominoFire avatar Sep 23 '22 04:09 dominoFire

This is so frustrating. I tried setting DOTNET_CLI_UI_LANGUAGE=en, killed all MSBuild processes, and I'm still getting compile errors in my system language, which is completely useless because every error on Google is in English.

I also tried deleting every cs folder I found among the many MSBuild folders I have from various .NET versions, but apparently that was too much and MSBuild is now crashing trying to load localized resource DLLs.

obrazek

Can't there be a simple way to just stop localizing output? I'm sure there are a few people who find this useful so it doesn't have to be the default, but I think for the majority of non-American programmers, this is really not helpful at all.

chylex avatar Oct 11 '22 11:10 chylex

Agree. At least you can search few results with the localized message in StackOverflow ;-(

hcoona avatar Oct 12 '22 13:10 hcoona

@hcoona I will add that you can usually search for the error code and copy the actual English error from Microsoft's documentation, which sounds like it would not be a lot of extra steps, but in reality it goes more like this:

  1. Search the error code on Google.
  2. Visit a Microsoft documentation page for the error.
  3. Be automatically redirected to a localized version of the documentation. I'm not sure about compiler errors specifically, but most times these "localized" documentation pages are actually machine-translated, which means there are many grammatical errors and mistranslations which actively harm the understandability of your documentation for foreigners.
  4. Manually switch the website language to English.
  5. Finally you can copy/paste the actual error message into Google.

I'm sorry, but this whole thing is a terrible user experience.

chylex avatar Oct 12 '22 15:10 chylex

I agree the UX is quite poor. I have been working to improve the UX in the .NET SDK/CLI, hoping to give it a try and migrate that same code here. Once that's been approved there.

nagilson avatar Jan 06 '23 22:01 nagilson

Setting DOTNET_CLI_UI_LANGUAGE=en helped for me.

sidorov-alex avatar Jan 21 '23 09:01 sidorov-alex

I already set DOTNET_CLI_UI_LANGUAGE=en and I'm still getting this...

obrazek

chylex avatar Jan 25 '23 01:01 chylex

@chylex My configuration:

  • Windows 11 + VS Code 1.74.3
  • .NET 7.0.102
  • I've set environment variable for user in system settings DOTNET_CLI_UI_LANGUAGE=en
  • For build I execute "dotnet build"
  • My system language is Russian

Output:

Executing task: C:\Program Files\dotnet\dotnet.exe build D:\Work\BadBroker/BadBroker/BadBroker.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary

MSBuild version 17.4.1+9a89d02ff for .NET Determining projects to restore... All projects are up-to-date for restore. D:\Work\BadBroker\BadBroker\Program.cs(25,5): error CS1061: 'WebApplication' does not contain a definition for 'Ru nnn' and no accessible extension method 'Runnn' accepting a first argument of type 'WebApplication' could be found (are you missing a using directive or an assembly reference?) [D:\Work\BadBroker\BadBroker\BadBroker.csproj]

  • The terminal process "C:\Program Files\dotnet\dotnet.exe 'build', 'D:\Work\BadBroker/BadBroker/BadBroker.csproj', '/property:GenerateFullPaths=true', '/consoleloggerparameters:NoSummary'" terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

As you can see there is only English output.

If I delete DOTNET_CLI_UI_LANGUAGE environment variable then output looks like:

Executing task: C:\Program Files\dotnet\dotnet.exe build D:\Work\BadBroker/BadBroker/BadBroker.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary

MSBuild version 17.4.1+9a89d02ff for .NET Определение проектов для восстановления... Все проекты обновлены для восстановления. D:\Work\BadBroker\BadBroker\Program.cs(25,5): error CS1061: "WebApplication" не содержит определения "Runnn", и не удалось найти доступный метод расширения "Runnn", принимающий тип "WebApplication" в качестве первого аргумента ( возможно, пропущена директива using или ссылка на сборку). [D:\Work\BadBroker\BadBroker\BadBroker.csproj]

  • The terminal process "C:\Program Files\dotnet\dotnet.exe 'build', 'D:\Work\BadBroker/BadBroker/BadBroker.csproj', '/property:GenerateFullPaths=true', '/consoleloggerparameters:NoSummary'" terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

sidorov-alex avatar Jan 25 '23 04:01 sidorov-alex

Note: This only work for msbuild using dotnet build. Calling msbuild directly does not honor the language.

Seikilos avatar Jan 25 '23 07:01 Seikilos

This should be added & fixed in 8.0 preview 5!

nagilson avatar May 09 '23 22:05 nagilson

Not working for me in .NET 8... I have the DOTNET_CLI_UI_LANGUAGE=en environment variable set on my whole user, but compile errors are still in Czech...

I ended up going into C:\Program Files\dotnet\sdk\8.0.100, deleting every single folder named cs, then restoring some of them that were in analyzers folders because it can't just fallback to english for some reason, but at least the compile errors are finally in English.

image

chylex avatar Dec 19 '23 00:12 chylex

Strangely, this only made MSBuild output, which was previously also localized, fallback to English, but the actual (I assume, dotnet) error message is still in Czech.

I've also noticed that the DOTNET_CLI_UI_LANGUAGE=en only works when I use dotnet build in CL directly. If I build the project in Rider, theoutput is still in system's language, despite Rider detecting the env variable in Run Configuration and JetBrains stating "build console output in Rider returns the same content as of running dotnet build manually".

I'm a bit lost here and quite frustrated. Why would anyone want development tools to be localized?

image

Not working for me in .NET 8... I have the DOTNET_CLI_UI_LANGUAGE=en environment variable set on my whole user, but compile errors are still in Czech...

I ended up going into C:\Program Files\dotnet\sdk\8.0.100, deleting every single folder named cs, then restoring some of them that were in analyzers folders because it can't just fallback to english for some reason, but at least the compile errors are finally in English.

image

adam-zluva avatar Jan 08 '24 11:01 adam-zluva

Not working for me in .NET 8... I have the DOTNET_CLI_UI_LANGUAGE=en environment variable set on my whole user, but compile errors are still in Czech...

It looks like MSBuild's messages are in English but the C# compiler's are in Czech. @nagilson, does DOTNET_CLI_UI_LANGUAGE not imply that the CLI sets the variables that Roslyn checks for?

I ended up going into C:\Program Files\dotnet\sdk\8.0.100, deleting every single folder named cs, then restoring some of them that were in analyzers folders because it can't just fallback to english for some reason, but at least the compile errors are finally in English.

To make things extra confusing, some of those cs mean C# and some mean Czech.

rainersigwald avatar Jan 08 '24 15:01 rainersigwald

Why would anyone want development tools to be localized?

Opinions on this vary widely, by individual dev and by culture--as I understand it many Europeans are on the "just give us English" side and many East Asian folks are strongly on "if it's in English it's useless, give me a translation". So we have to try to find compromises.

I've also noticed that the DOTNET_CLI_UI_LANGUAGE=en only works when I use dotnet build in CL directly. If I build the project in Rider, theoutput is still in system's language, despite Rider detecting the env variable in Run Configuration and JetBrains stating "build console output in Rider returns the same content as of running dotnet build manually".

You'll have to take this up with JetBrains, that sounds like a Rider bug (or doc bug) to me.

rainersigwald avatar Jan 08 '24 15:01 rainersigwald

It looks like MSBuild's messages are in English but the C# compiler's are in Czech. @nagilson, does DOTNET_CLI_UI_LANGUAGE not imply that the CLI sets the variables that Roslyn checks for?

@rainersigwald There is no logic to set a special variable for Roslyn in the SDK or MSBuild to my knowledge (which should be most of the code.) I was not aware they had their own language variable, is that the case? It does set VSLANG.

nagilson avatar Jan 08 '24 17:01 nagilson

I would have expected VSLANG to do it . . .

rainersigwald avatar Jan 08 '24 17:01 rainersigwald

I looked at it again since its been a while. Actually, it looks like it sets PreferredUILang too, which it says is for C#/VB. https://github.com/dotnet/sdk/blob/main/src/Cli/Microsoft.DotNet.Cli.Utils/UILanguageOverride.cs But it does only set those things if it detects a language override, which It should in this case. May be helpful to get a aka.ms//binlog. If the user had set VSLANG or PreferredUILang, as well to something else, then it would NOT override that.

nagilson avatar Jan 08 '24 17:01 nagilson

Opinions on this vary widely, by individual dev and by culture--as I understand it many Europeans are on the "just give us English" side and many East Asian folks are strongly on "if it's in English it's useless, give me a translation". So we have to try to find compromises.

Then maybe having English as default for Europeans would be a better compromise? I'm repeatedly frustrated with Microsoft's approach to localization of development tools, such as MSDN (Microsoft Learn?) randomly forcing terrible machine translations of documentation pages, which aren't even consistent with the translations in MSBuild / Roslyn, making it even more difficult to find anything!

For example, Adam's example error message "Očekával se středník (;)." is apparently translated on https://learn.microsoft.com/cs-cz/dotnet/csharp/misc/cs1002 as "; Očekává", which is complete nonsense. Not to mention that comments in the example code on that page are still in English. This is not helpful at all.

If you're not going to do localization properly, then don't make it the default option. If you are doing proper localization for East Asian languages, and they have a lot of resources on the internet in their language so it's easier for them to find help, then sure, default to localized for them. For my small european country in particular, this is not the case at all, and all it's doing is hurting communication and searchability.

chylex avatar Jan 08 '24 22:01 chylex

To be clear:

  1. MSBuild will continue to be localized by default.
  2. It should be easy to opt out of this, which should be the case in 17.9/8.0.200 (pending release) thanks to https://github.com/dotnet/msbuild/pull/9392.
  3. There may be bugs in certain scenarios or with certain tools. Please report them!
  4. For quality-of-translation issues, please file bugs on individual repos (but be aware that they'll need to be mirrored to the internal Microsoft loc bug tracking system and then triaged and fixed by the Microsoft loc team).

rainersigwald avatar Jan 12 '24 21:01 rainersigwald

To clarify: we should expect everything in the build process to respect DOTNET_CLI_UI_LANGUAGE=en, and open new issues (on the corresponding component issue tracker: e.g. Roslyn, .NET SDK, etc.) if something misbehaves in this mode. Correct?

ForNeVeR avatar Jan 12 '24 21:01 ForNeVeR