如何为WinForm应用程序创建全局资源文件

本文关键字:全局 资源 源文件 创建 应用程序 WinForm | 更新日期: 2023-09-27 18:16:49

我需要为不同的项目使用相同的资源文件。

我的资源文件名为Resource1.resx我用resgen创建了一个。resources扩展文件,用。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.

如何解决这个问题?

如何为WinForm应用程序创建全局资源文件

您正在从执行程序集中加载资源,但正如您提到的,您已在单独的程序集中定义了资源。

你应该把它指向你的资源dll而不是执行程序集。