如何在ASP.NET MVC中使用编制的全球资源 [英] How to use compiled global resources in ASP.NET MVC

查看:167
本文介绍了如何在ASP.NET MVC中使用编制的全球资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要编译的 App_GlobalResources文件/ Strings.resx 的到我的组件(最终使用卫星组合件的 Strings.es.resx,Strings.fr.resx 的等。 ),但一旦应用发布后出现以下错误:

I want to compile App_GlobalResources/Strings.resx into my assembly (and eventually use satellite assemblies for Strings.es.resx, Strings.fr.resx, etc.) but the following error occurs once the app is published:

无法加载文件或程序集'App_GlobalResources文件'或它的一个依赖该系统找不到指定的文件。

"Could not load file or assembly 'App_GlobalResources' or one of its dependencies. The system cannot find the file specified."

重现步骤:


  1. 创建一个新的ASP.NET MVC项目。

  2. 添加App_GlobalResources文件夹和 Strings.resx 的文件。

  3. 设置文件的生成操作为嵌入的资源

  4. 添加一个字符串的 Strings.resx 的和 HomeController.Index使用(),例如计算机[消息] = Strings.MyTest

  5. F5调试,运行良好。

  6. 发布到IIS和(因为 Strings.resx 的是从发布除外),你会在发布的站点出现上述错误。

  1. Create a new ASP.NET MVC project.
  2. Add an App_GlobalResources folder and a Strings.resx file.
  3. Set the file's build action to 'Embedded Resource'
  4. Add a string to Strings.resx and use it in HomeController.Index(), e.g. ViewData["Message"] = Strings.MyTest
  5. F5 to debug, works fine.
  6. Publish to IIS and (since Strings.resx is excluded from publishing) you will get the above error in the published site.

能否ASP.NET MVC项目中使用编译成DLL字符串资源,如果是这样,我究竟做错了什么?

更新:这是我在看到反射:

Update: Here is what I see in Reflector:

那么,为什么的ResourceManager 没有找到他们?是不是应该<一个href=\"http://msdn.microsoft.com/en-us/library/system.resources.ultimateresourcefallbacklocation.aspx\"相对=nofollow>回退到默认主组件?

So why is the ResourceManager not finding them? Isn't it supposed to fallback to the main assembly by default?

推荐答案

下面是一个很好的起点,<一个href=\"http://odeto$c$c.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx\">http://odeto$c$c.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

Here's a good starting point http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

我建立的一个项目就像你提到的,当我部署到IIS6了precisely同样的错误。更改自定义工具 PublicResXFile codeGenerator 自定义工具命名空间资源清除它的权利了。

I setup a project just like you mentioned and got precisely the same error when I deployed to IIS6. Changing Custom Tool to PublicResXFileCodeGenerator and Custom Tool Namespace to Resources per Scott's suggestions cleared it right up.

我想也直言如下斯科特的铅消除App_GlobalResources文件,但我得到它的工作就好了。这可能是个人的preference的问题。

I'd also follows Scott's lead with respect to eliminating App_GlobalResources but I got it to work just fine. That might be a matter of personal preference.

这篇关于如何在ASP.NET MVC中使用编制的全球资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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