为什么在单元测试中找不到resx文化? [英] Why are resx cultures not found in unit tests?
问题描述
我在.NET 4.0项目中嵌入了字符串资源:Strings.resx和Strings.de.resx。
I have embedded string resources in my .NET 4.0 project: Strings.resx and Strings.de.resx.
在生产代码中取决于Strings.Culture的值,可以检索正确的本地化字符串。
In production code the correct localised strings are retrieved, dependent on the value of Strings.Culture:
Strings.Culture = new Culture("de");
string deString = Strings.Welcome; // 'Willkommen'
Strings.Culture = new Culture("en");
string enString = Strings.Welcome; // 'Welcome'
但是在我的单元测试代码中(使用MSTest )永远不会返回'Strings.de.resx'中的字符串-不论 Strings.Culture
或 Threads.CurrentThread.CultureUICulture
。
But in my unit test code (using MSTest) the strings from 'Strings.de.resx' are never returned - I only ever get the strings from Strings.resx, no matter what the values of Strings.Culture
or Threads.CurrentThread.CultureUICulture
.
有人可以帮忙吗?
推荐答案
好,我能够重现此问题。首先尝试禁用部署。转到 local.testsettings,然后取消选中部署->启用部署。选中此标志后,VS似乎没有为我部署附属程序集。
如果确实需要一些部署项目,请使用DeploymentItemAttribute:
Ok, I was able to reproduce this issue. First of all try to disable deployment. Go to "local.testsettings" and uncheck Deployment -> Enable Deployment. When this flag is checked, VS doesn't seem to be deploying satellite assemblies for me. If you do need some deployment item, use DeploymentItemAttribute:
[DeploymentItem(
@".\YourProject\bin\Debug\de\YourProject.resources.dll", @".\de\")]
或使用相同的部署标签来选择适当的附属程序集。
or use the same "Deployment" tab to select appropriate satellite assemblies.
这篇关于为什么在单元测试中找不到resx文化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!