Gar*_*wen 7 c# unit-testing embedded-resource
我在.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'
Run Code Online (Sandbox Code Playgroud)
但是在我的单元测试代码中(使用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\")]
Run Code Online (Sandbox Code Playgroud)
或使用相同的"部署"选项卡选择适当的附属程序集.
| 归档时间: |
|
| 查看次数: |
1721 次 |
| 最近记录: |