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

拥有回忆 提交于 2019-12-06 16:44:20

问题


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:

  • VB.Net compiler params
  • C# compiler params

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")

回答1:


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.



来源:https://stackoverflow.com/questions/32668403/instruct-codedomprovider-compiler-to-show-errors-and-warning-messages-in-english

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!