c# – 为什么在单元测试中找不到resx文化?
发布时间:2020-12-15 08:06:08 所属栏目:百科 来源:网络整理
导读:我在.NET 4.0项目中嵌入了字符串资源:Strings.resx和Strings.de.resx. 在生产代码中,将检索正确的本地化字符串,具体取决于Strings.Culture的值: Strings.Culture = new Culture("de");string deString = Strings.Welcome; // 'Willkommen'Strings.Culture
我在.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' 但是在我的单元测试代码中(使用MSTest),永远不会返回’Strings.de.resx’中的字符串 – 我只能从Strings.resx获取字符串,无论Strings.Culture或Threads.CurrentThread.CultureUICulture的值是什么. 有人可以帮忙吗? 解决方法
好的,我能够重现这个问题.首先尝试禁用部署.转到“local.testsettings”并取消选中Deployment – >启用部署.选中此标志后,VS似乎没有为我部署附属程序集.
如果确实需要某个部署项,请使用DeploymentItemAttribute: [DeploymentItem( @".YourProjectbinDebugdeYourProject.resources.dll",@".de")] 或使用相同的“部署”选项卡选择适当的附属程序集. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |