gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET MVC 中使用已编译的全局资源

转载 作者:行者123 更新时间:2023-12-03 21:27:28 24 4
gpt4 key购买 nike

我想将 App_GlobalResources/Strings.resx 编译到我的程序集中(并最终将附属程序集用于 Strings.es.resx、Strings.fr.resx 等),但是一旦应用程序发布,就会发生以下错误:

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



重现步骤:
  • 创建一个新的 ASP.NET MVC 项目。
  • 添加 App_GlobalResources 文件夹和 Strings.resx 文件。
  • 设置文件的 对“嵌入式资源”的构建操作
  • 将字符串添加到 Strings.resx 并在 HomeController.Index() 中使用它,例如ViewData["Message"] = Strings.MyTest
  • F5 调试,工作正常。
  • 发布到 IIS 并且(因为 Strings.resx 从发布中排除)您将在发布的站点中收到上述错误。

  • ASP.NET MVC 项目可以使用编译到 dll 中的字符串资源吗?如果可以,我做错了什么?

    更新:这是我在 Reflector 中看到的:
    String Resources

    那么为什么是 ResourceManager没有找到他们?是不是应该 fallback to the main assembly默认情况下?

    最佳答案

    这是一个很好的起点 http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

    我像您提到的那样设置了一个项目,并且在部署到 IIS6 时遇到了完全相同的错误。换 Custom ToolPublicResXFileCodeGeneratorCustom Tool NamespaceResources根据 Scott 的建议,它马上就解决了。

    我也遵循 Scott 在消除 App_GlobalResources 方面的领导,但我让它工作得很好。这可能是个人喜好的问题。

    关于asp.net-mvc - 如何在 ASP.NET MVC 中使用已编译的全局资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1848955/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com