为什么在unit testing中找不到resx文化?
我在.NET 4.0项目中嵌入了字符串资源:Strings.resx和Strings.de.resx。
在生产代码中 ,将检索正确的本地化字符串,具体取决于Strings.Culture的值:
Strings.Culture = new Culture("de"); string deString = Strings.Welcome; // 'Willkommen' Strings.Culture = new Culture("en"); string enString = Strings.Welcome; // 'Welcome'
但是在我的unit testing代码中 (使用MSTest),永远不会返回’Strings.de.resx’中的字符串 – 我只能从Strings.resx获取字符串,无论Strings.Culture
或Threads.CurrentThread.CultureUICulture
的值是什么。
有人可以帮忙吗?
好的,我能够重现这个问题。 首先尝试禁用部署。 转到“local.testsettings”并取消选中Deployment – > Enable Deployment。 选中此标志后,VS似乎没有为我部署附属程序集。 如果确实需要某个部署项,请使用DeploymentItemAttribute:
[DeploymentItem( @".\YourProject\bin\Debug\de\YourProject.resources.dll", @".\de\")]
或使用相同的“部署”选项卡选择适当的附属程序集。