将资源文件编译到库时出现问题
我有一个用asp.net构建的Web应用程序,它使用资源文件来支持多种语言。 我遇到的问题是我只能在 Visual Studio 中添加新的语言文件,并且我必须重建整个应用程序才能包含新的语言。 在网上搜索后我发现资源文件的编译可以在.net编译器中完成。 我使用了以下命令:
resgen.exe /compile langfile.en.resx
al.exe /out:en\App_GlobalResources.resources.dll /culture:en /embedresource:langfile .en.resources
该文件已复制到网站的文件夹中,但不起作用。 我的意思是,当我从网页中选择新语言时,将从默认资源文件中加载字符串。 如果我在VS中创建资源文件,它就可以正常工作。 我检查了两个dll文件的大小,一个是VS生成的,一个是我自己编译的,它们大小相同,但编译后的不行。 我只能认为也许我必须在上面的命令中使用一些其他参数,但我真的不知道。
非常感谢任何帮助。
I have a web application built in asp.net, which uses resource files to support multiple languages. The problem I have is that I can only add a new language file in Visual Studio, and I have to rebuild the whole application to have a the new language included. After searching the net I've found out that the compilation of the resource files can be done in the .net compiler. I've used the following commands:
resgen.exe /compile langfile.en.resx
al.exe /out:en\App_GlobalResources.resources.dll /culture:en /embedresource:langfile
.en.resources
The file is copied into the website's folder but it doesn't work. I mean, when I select the new language from the web page, the strings are loaded from the default resource file. If I create the resource file in VS, it works okay. I checked the sizes of the two dll files, the one generated by VS and the one compiled by myself, and they have the same size but the compiled one doesn't work. I can only think that maybe I would have to use some other parameters in the commands above but I don't really know.
Any help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过编写自己的表达式生成器(而不是使用内置资源版本)并从数据库或 XML 文件中提取信息来实现您想要的目的。 基本上,您编写自己的类,继承自 System.Web.Compilation.ExpressionBuilder,然后像这样在 Web.config 中注册它:
然后您可以像普通资源一样引用它:
您可以找到一些关于此的文章 此处 和此处。
You can achieve what you want by writing your own expression builder instead of using the built-in resources version and pull the information from a database or XML files. Basically you write your own class inheriting from System.Web.Compilation.ExpressionBuilder and then register it in Web.config like this:
and then you can reference it like normal resources:
You can find some articles on this here and here.