简体   繁体   English

使用Visual Studio 2010在程序集中添加资源文件

[英]Adding resources file in an assembly using visual studio 2010

I wanted to have culture specific resources in my application. 我想在我的应用程序中包含特定于文化的资源。 What i did is i created a Resource.txt and compile this to Resource.resources using resgen.exe. 我所做的是我创建了Resource.txt,并使用resgen.exe将其编译为Resource.resources。

However, if i access my resource using: 但是,如果我使用以下方法访问资源:

System.Resources.ResourceManager rm = new System.Resources.ResourceManager("ResourceManager.Resources",
                             Assembly.GetExecutingAssembly());

and if i will call Console.WriteLine(rm.GetString("test")); 如果我将调用Console.WriteLine(rm.GetString("test")); it will throw an error 它将引发错误

Could not find any resources appropriate for the specified culture or the neutral culture. 找不到适合于指定区域性或中性区域性的任何资源。 Make sure "ResourceManager.Resources.resources" was correctly embedded or linked into assembly "ResourceManager" at compile time, or that all the satellite assemblies required are loadable and fully signed. 确保在编译时已将“ ResourceManager.Resources.resources”正确嵌入或链接到程序集“ ResourceManager”中,或者确保所需的所有附属程序集都可加载并经过完全签名。

My resource file is Resources.txt with text inside "test=testing" and will be compiled into Resources.resources. 我的资源文件是Resources.txt,其中“ test = testing”中包含文本,并将被编译成Resources.resources。

Question: 题:

  1. How can i link the compiled resources to the assembly using the IDE(Visual Studio 2010)?, not using the csc, or AL on command line. 如何使用IDE(Visual Studio 2010)将编译的资源链接到程序集?而不是在命令行上使用csc或AL。

  2. Is there any other recommended way how to accomplish this? 还有其他建议的方式来完成此操作吗? I have added .resx files in visual studio and its working, however its not favorable for me, i favored the txt file with key=value type set up. 我已经在Visual Studio中添加了.resx文件及其工作方式,但是它对我不利,我更喜欢设置key = value类型的txt文件。

Try to use 尝试使用


System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Resources",
                             Assembly.GetExecutingAssembly());

instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM