2012-02-28 52 views
7

我在.NET 4.0項目中嵌入了字符串資源:Strings.resx和Strings.de.resx。爲什麼在單元測試中找不到resx文化?

生產代碼正確本地化字符串檢索,取決於Strings.Culture的值:

Strings.Culture = new Culture("de"); 
string deString = Strings.Welcome; // 'Willkommen' 
Strings.Culture = new Culture("en"); 
string enString = Strings.Welcome; // 'Welcome' 

但在我單元測試代碼(使用MSTest的)從「字符串的字符串。 de.resx'永遠不會被返回 - 我只能從Strings.resx獲取字符串,無論Strings.CultureThreads.CurrentThread.CultureUICulture的值如何。

任何人都可以幫忙嗎?

+0

這通常意味着衛星組件不會被部署。你使用什麼測試框架?對於MSTest,一切似乎都已正確部署。如果不是,可以使用DeploymentItemAttribute。 – 2012-03-02 09:49:00

+0

我正在使用MSTest(相應更新的問題)。 resx文件在正在測試的程序集中具有Build Action ='Embedded Resource'。我應該如何使用DeploymentItemAttribute? – GarethOwen 2012-03-02 12:03:54

回答

7

好的,我能夠重現此問題。首先嚐試禁用部署。轉到「local.testsettings」並取消選中部署 - >啓用部署。當這個標誌被選中時,VS似乎沒有爲我部署衛星組件。 如果你確實需要一些部署項目,使用DeploymentItemAttribute:

[DeploymentItem(
    @".\YourProject\bin\Debug\de\YourProject.resources.dll", @".\de\")] 

或使用相同的「部署」選項卡中選擇適當的附屬程序集。

+0

感謝您的幫助 - 我會嘗試一下 – GarethOwen 2012-03-02 12:40:07

相關問題