在类库项目中使用Resource .resx文件 [英] Using Resource .resx file in Class library project

查看:106
本文介绍了在类库项目中使用Resource .resx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类库项目中使用了资源文件(.resx)文件来存储一些错误消息.当我将resx文件的构建操作"设置为嵌入式资源"并部署时,它工作正常.但是我想将资源文件与dll分开,因为将来可能需要更改resx文件中的错误消息,而无需重新编译类库项目.我在构建操作"属性的内容,资源等中尝试了其他选项,但是似乎没有任何方法可以按照我的要求进行.当我使用这些属性时,出现以下错误,

I have used resource file(.resx) file in a class library project to store some error messages. When I set the "Build Action" to "Embedded Resource" for the resx file and deploy it works fine. But I would like to separate the resource file from the dll since I may need to change the error messages in resx file in future without the need to recompiling the class library project. I tried the other option in "Build Action" property Content,resource, etc but nothing seems to be working in the way I require. When I use these property I am getting the below error,

<代码>找不到适合于指定区域性或中性区域性的任何资源.确保在编译时已正确地嵌入或链接到程序集,或者确保所需的所有附属程序集都可加载并经过完全签名.

有什么办法可以解决此错误并使其正常工作?

Is there any way to resolve this error and make it work?

推荐答案

必须将资源文件设置为嵌入式-这就是它们的工作方式.

Resource files have to be set to embedded - that's how they work.

您可以创建另一个包含资源的程序集并对其进行引用-这样,您可以重新部署更新的资源.它需要在代码中做更多的工作(加载程序集以便能够获得嵌入式资源).

You can create another assembly containing the resources and reference it - this way you can redeploy the updated resources. It requires a bit more work in your code (loading the assembly in order to be able to get the embedded resources).

但是,从您的描述(部署后需要可编辑的文本消息)来看,也许将它们存储在配置中是一个更好的选择(特别是如果您不进行本地化的话).

However, from your description (text messages that need to be editable after deployment), perhaps storing these in configuration is a better option (in particular if you are not localizing).

这篇关于在类库项目中使用Resource .resx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆