[英]How to debug in a different locale in VS2017
I have a nasty bug which manifests itself only when I run my C# program on a non-english Windows. 我有一个讨厌的错误,仅当我在非英语的Windows上运行C#程序时才会显示出来。 It is a conversion from double to string (I get commas instead of dots on some values we shouldn't localize).
它是从双精度到字符串的转换(我得到逗号而不是一些我们不应该本地化的值上的点)。 In order to test the fix (ie applying
InvariantLocale
everywhere) I need to build the executable and run it on a non-english VM, it's very time consuming. 为了测试此修复程序(即在所有位置应用
InvariantLocale
),我需要构建可执行文件并在非英语VM上运行它,这非常耗时。
My question is: is it possible to debug inside VS2017 pretending to be on a non-english Windows environment? 我的问题是:是否可以在伪装成非英语的Windows环境中进行VS2017内部调试? (let's say for example a Dutch Windows)
(例如,使用荷兰语Windows)
I use a utility class for setting the language: 我使用实用程序类来设置语言:
public static class LanguageSetter
{
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
private static extern ushort SetThreadUILanguage(ushort _languageId);
public static void SetLanguage(string uiLanguage)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(uiLanguage);
SetThreadUILanguage((ushort) Thread.CurrentThread.CurrentUICulture.LCID);
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo(uiLanguage);
}
}
Just call it with LanguageSetter.SetLanguage("nl-NL");
只需使用
LanguageSetter.SetLanguage("nl-NL");
调用即可LanguageSetter.SetLanguage("nl-NL");
If you use WPF, add another line at the end of that function: FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.IetfLanguageTag)));
如果使用WPF,请在该函数的末尾添加另一行:
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.IetfLanguageTag)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.