Instruct CodeDomProvider compiler to show errors and warning messages in English language?
Asked Answered
P

1

25

I'm using the System.CodeDom features to compile code at run time and I wonder if I could specify a compiler parameter or other workaround to display the compiler errors in English language instead of using the system's default language.

However, in the MSDN documentation I can't find anything related to the displayed language:

When I want to display compiler errors in a specific language under Visual Studio IDE when building a project what I do is change the current culture, then I tried to set the culture in my application and also inside the file that I'm compiling from my application, but firstly that does not take effect, and secondly I prefer to avoid possible tricks like this, because possibly it will require automated code generation (imports, references, and code when calling CodeDomProvider compiler):

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-Us")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-Us")
Primal answered 19/9, 2015 at 12:49 Comment(8)
At least for C#, have you tried the /preferreduilang switch?Keys
@Keys Thanks that worked ...only for the C# compiler, but what happens for the VB.Net compiler? really it doesn't exist an option for this?.Primal
That option is relatively recent for C# (VS2012). I don't have an answer for VB; the /preferreduilang shows up in the VS2015 doc's for VB as an entry, but I don't know if it works and I do not have VS2015 installed to try it.Keys
@Keys It works with the VBC.EXE compiler that ships with VS2015 (not with the one that comes with VS2013) though.Gleiwitz
The /preferreduilang is not featured in the command help of the .NetFx v4.0 compiler (vbc.exe) neither in the online MSDN docs, also it doesn't works when adding the mentioned parameter using the VBCodeProvider (again using the .NetFx v4.0 compiler or lower), someone could give some light to this? maybe for the version 4.5.X that parameter works?.Primal
@Gleiwitz has verified that the switch works with VS2015 (.Net 4.6).Keys
CodeDom executes the compiler in System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory. You can see this yourself in Executor.cs, GetRuntimeInstallDirectory method)Keys
@Keys I think you should post that as an answer.Milksop
K
2

You probably should use CompilerParameters.CompilerOptions property. If you open link you may find example there. You need to change preferreduilang parameter. To set output language to English use "/preferreduilang:en-US" option. Keep in mind that it would not work for languages which are not installed in your system.

Karilynn answered 4/5, 2016 at 8:10 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewLatex
I am sorry, but I guess it is a bit of misunderstanding. As I understand, I gave essential part in my answer. I.e. I wrote class name, property name, which value it should be set to and which condition (language is installed in the system) should be met to make sure it works. Links just contain some additional info. First one contains code snippet, which could be used as an example. As for second one, I agree it is not necessary, I'm just removing it cause it does not add any value. Hope now it's better. Thank you.Karilynn

© 2022 - 2024 — McMap. All rights reserved.