Why are resx cultures not found in unit tests?

余生长醉 提交于 2019-12-22 05:02:07

问题


I have embedded string resources in my .NET 4.0 project: Strings.resx and Strings.de.resx.

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'

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.

Can anybody help?


回答1:


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.



来源:https://stackoverflow.com/questions/9484355/why-are-resx-cultures-not-found-in-unit-tests

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