MVC App_GlobalResources,使用本地和发布 [英] MVC App_GlobalResources, use local and publish

查看:250
本文介绍了MVC App_GlobalResources,使用本地和发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对GlobalResources有问题

I have a problem with GlobalResources

  1. 我创建App_GlobalResources文件夹
  2. 添加User.resx
  3. 添加名称=名字",值=名字"

默认情况下,我无法在MVC项目中使用此资源. 我试过了:

Default I can't use this resources in my MVC project. I tried:

  • App_GlobalResources.User.FirstName-无效
  • Resources.User.FirstName-它可以工作,但仅在代码隐藏时,在构建和启动应用程序(本地)时显示错误:

Niemożnapobraćwłaściwości名字",ponieważlokalizacja niepowiodłasię.键入"Resources.Users" nie jest publiczny lub nie zawiera publicznej,statycznejwłaściwościciąguo nazwie"FirstName".

Nie można pobrać właściwości „Name", ponieważ lokalizacja nie powiodła się. Typ „Resources.Users" nie jest publiczny lub nie zawiera publicznej, statycznej właściwości ciągu o nazwie „FirstName".

其翻译是:

由于位置失败,无法检索属性名称".类型"Resources.Users"不是公共的,或者在名为"FirstName"的内部不包含公共静态属性.

Unable to retrieve the properties "Name" as the location failed. Type "Resources.Users" is not a public or does not contain a public static property within named "FirstName."

然后我更改User.resx属性:

Then I change User.resx properties:

  • 构建操作:嵌入式资源
  • 复制到输出:目录不复制
  • 自定义工具:PublicResourceProxyGenerator
  • 自定义工具命名空间:空"

现在我不能使用 Resources.User.First ,我必须 useApp_GlobalResources.User.FirstName

Now I can't use Resources.User.FirstName I have to useApp_GlobalResources.User.FirstName

我很高兴它正在工作.但是昨天是我第一次在测试服务器上发布,资源无法使用...

I'm happy it's work. But yesterday is my first publish on the test server and resourses not working...

文件未复制到服务器...

File does't copy to server...

我更改了User.resx属性

I change User.resx properties

  • 构建操作:内容
  • 复制到输出:目录不复制
  • 自定义工具:GlobalResourceProxyGenerator
  • 自定义工具命名空间:空"

复制文件,但是应用程序抛出了我上面共享的相同的先前异常,并且资源在本地计算机上不起作用,有什么建议吗?

Copy files but the application throws the same previous exception which I shared above and resources not work in localmachine, any advice?

推荐答案

请考虑以下有关资源的注释:

Consider these notes about resources:

当您将资源文件添加到ASP.NET项目的App_GlobalResources特殊文件夹中时,将使用GlobalResourceProxyGenerator自定义工具来处理您的资源,并且它将在Resources命名空间中生成一个internal类. App_GlobalResources程序集,用于管理资源.

When you add a resource file to the App_GlobalResources special folder of an ASP.NET project, the GlobalResourceProxyGenerator custom tool will be used for your resource and it will generates an internal class in Resources namespace in App_GlobalResources assembly for managing resource.

  • 这类资源是内部资源,不能更改其访问修饰符.
  • 它们不能用于数据注释属性,如[Display]或验证属性.

  • These kind of resources are internal and their access modifier can not be changed.
  • They can not be used for data annotations attributes like [Display] or validation attributes.

可以通过调用Resources.ResourceFile.ResourceProperty在View或代码中直接使用它们.

They can be used in View or code directly by calling Resources.ResourceFile.ResourceProperty.

使用ResXFileCodeGenerator作为自定义工具的嵌入式资源将在默认命名空间+文件夹层次结构的命名空间中生成公共资源文件.

An embedded resource with ResXFileCodeGenerator as custom tool, will generate a public resource file in a namespace which is default namespace + folder hierarchy.

  • 默认情况下,此类资源是公共的,但是您可以使用设计器更改它们的访问修饰符.您也可以通过更改其Custom Tool Namespace属性在自定义命名空间中生成它们.

  • These kind of resources are public by default but you can change the access modifier of them using designer. Also you can generate them in a custom namespace by changing their Custom Tool Namespace property.

它们可用于数据注释属性,例如[Display]或验证属性.

They can be used for data annotations attributes like [Display] or validation attributes.

可以通过调用SomeNamespace.ResourceFile.ResourceProperty在View或代码中直接使用它们.

They can be used in View or code directly by calling SomeNamespace.ResourceFile.ResourceProperty.

这篇关于MVC App_GlobalResources,使用本地和发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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