如何发布/部署一个MVC项目与资源的ResX? [英] How do I publish/deploy an MVC Project with ResX Resources?

查看:197
本文介绍了如何发布/部署一个MVC项目与资源的ResX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这只是显示从资源文件一个字符串一个非常简单的MVC应用程序。它工作得很好,我的本地机器上,但是当我将项目部署到Web服务器出现错误。

I have written a VERY simple MVC application which just displays a single string from a Resource file. It works just fine on my local machine but when I deploy the project to the web server I get the error.

CS0103:名称'资源'不
  存在于当前上下文

CS0103: The name 'Resources' does not exist in the current context

您可以很容易复制的正是我在短短的10个步骤在做!

You can very easily replicate exactly what I am doing in just 10 steps!


  1. 创建新的MVC 2的Web应用程序。

    (文件 - >新建 - >项目 - > ASP.NET MVC 2 Web应用程序,说没有单元测试项目)

  1. Create a New MVC 2 Web Application.
    (File->New->Project->ASP.NET MVC 2 Web Application, say no to the Unit Testing Project)

添加App_GlobalResources文件文件夹中。
(右键单击该项目,并选择添加 - >添加ASP.NET文件夹 - > App_GlobalResources文件)

Add the "App_GlobalResources" folder.
(right click the project and select Add->Add ASP.NET Folder->App_GlobalResources)

添加资源文件到该文件夹​​。
(右键单击该文件夹并选择添加 - >新项...->资源文件,命名为Strings.resx )

Add a Resource File to this folder.
(right click the folder and select Add->New Item...->Resources File. Name it Strings.resx)

一个字符串添加到资源表。
(NAME =HelloWorld的,值=我本地化的Hello World!)

Add a single string to the Resource table.
(Name = "HelloWorld", Value = "I localized Hello World!")

设置为资源文件的文件属性。
(点击文件Strings.resx和int的属性窗口中设置生成操作=嵌入的资源和CustomTool = PublicResXFile codeGenerator)

Set the File Properties for the Resource File.
(Click the file Strings.resx and int the Properties window set Build Action = "Embedded Resource" and the CustomTool = "PublicResXFileCodeGenerator")

添加新控制器
(右键单击控制器文件夹并选择添加 - >控制器...将其命名为HelloWorldController.cs)

Add a new Controller
(Right click the Controllers folder and select Add->Controller... Name it HelloWorldController.cs)

添加视图
(光标在HelloWorldController.cs preSS CTRL-MV的指数方法,使用默认值,包括视图名称= 指数)

Add a the View
(With the cursor in the Index method of the HelloWorldController.cs Press CTRL-M-V. Use the default values including View name = "Index")

修改视图,以便它显示我们从资源文件的字符串。

<h2><%: Resources.Strings.HelloWorld %></h2>


  • 本地运行测试,它的作品。它应该。

    它发布到Web服务器和访问URL的http://本地主机/ HelloWorld的

    这是我看到在上面描述的错误。

    This is where I see the error described at the top.

    我会想象我穿上的ResX文件中的设置不正确,且资源不发布到服务器。

    I would imagine that the settings I've put on the ResX file are incorrect and the resource is not published to the server.

    帮助是极大的AP preciated。

    Help is greatly appreciated.

    谢谢!

    推荐答案

    啊哈!弄清楚了。在很大程度上这篇文章:

    <一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

    Ah ha! Figured it out. In LARGE part to this article:
    http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

    听起来就像是App_GlobalResources文件夹不与合作MVC。所以,我提出我的ResX文件到一个新的文件夹
    〜/资源/字符串 /Strings.resx

    Sounds like the App_GlobalResources folder is NOT cooperative with MVC. So I moved my ResX file to a new folder
    ~/Resources/Strings/Strings.resx

    这与1小的变化而设置文件属性

    自定义工具命名空间 =资源

    This along with 1 minor change to set the File Property
    Custom Tool Namespace = Resources

    和问题解决了!

    这篇关于如何发布/部署一个MVC项目与资源的ResX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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