2011-12-06 65 views
1

我需要爲不同的項目使用相同的資源文件。如何爲WinForm應用程序創建全局資源文件?

我的資源文件名命名爲Resource1.resx 我用RESGEN創建爲.resources擴展名的文件,我用Al.exe工具

產生.resources.dll但後來我嘗試使用在我的項目文件,我得到一個錯誤,我的代碼是類似於此:

ResourceManager resmgr = new ResourceManager("Resource1", 
           Assembly.GetExecutingAssembly()); 
string msg = resmgr.GetString("name"); 
MessageBox.Show(msg); 

的錯誤信息是這樣的:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resource1.resources" was correctly embedded or linked into assembly "WinTest" at compile time, or that all the satellite assemblies required are loadable and fully signed. 

如何解決這個問題?

回答

3

您正在從執行裝配中加載資源,但正如您所提到的,您已在單獨的裝配中定義了資源。

而不是執行程序集,你應該把它指向你的資源DLL。

+0

是的,我在同一個正在執行的程序集中創建了資源文件。並創建了.resources.dll文件。是否有必要使它成爲一個單獨的項目並創建一個資源的dll文件。 – niknowj

+0

我不完全理解你。你說你在執行程序集和單獨的resources.dll中都有資源? –

+0

是我知道了。我在我的一個項目中創建了資源文件。意味着我有兩個項目,比如project1和project2,在project1中我創建了資源文件。我想我需要將資源文件分成一個新的項目並編譯。謝謝。 – niknowj

相關問題