资源 (RESX) 文件混乱

发布于 2024-09-11 18:20:59 字数 323 浏览 4 评论 0原文

我有一个名为 Localize.resx 的资源文件,其中包含英文字符串。我将其复制并粘贴到同一文件夹(App_GlobalResources)中,VS 创建了一个副本,我将副本重命名为 Localize.sl.resx,将原始重命名为 Localize.en.resx。现在代码隐藏文件 (Localize.en.designer.cs) 中的所有内容都消失了。删除设计器文件并选择运行自定义工具会生成一个新的但完全空白的设计器文件。

我的所有字符串仍然存在于两个 resx 文件中,但设计器文件已消失(空),因此应用程序无法构建。

这是带有 ASP.NET MVC 解决方案的 VS 2010 内部。

I had a resource file named Localize.resx, which contains English strings. I copied and pasted it inside the same folder(App_GlobalResources), VS created a copy, I renamed the copy to Localize.sl.resx and the original to Localize.en.resx. Now everything in codebehind files (Localize.en.designer.cs) is gone. Deleting the designer file and selecting Run Custom Tool generates a new but completely blank designer file.

I still have all my strings in both resx files but the designer files are gone (empty) so the application does not build.

This is inside VS 2010 with an ASP.NET MVC solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我家小可爱 2024-09-18 18:20:59

这是ASP.NET 文档有关资源文件的内容。

它没有具体讨论动态生成的代码隐藏设计器文件,但如果您仔细阅读粗体文本,它本质上是说您需要没有指定语言的基本文件,并且考虑到这一点,只有这个文件将包含自动生成的文件是有意义的代码。

创建资源文件时,首先创建一个基本 .resx 文件。对于要支持的每种语言,创建一个具有相同文件名的新文件。但在名称中包含语言或语言和文化(区域性名称)。 有关区域性名称的列表,请参阅 CultureInfo 类。例如,您可以创建以下文件:

•WebResources.resx

这是默认的(后备)文件。 •

•WebResources.es.resx

西班牙语资源文件

WebResources.es-mx.resx

用于西班牙语(墨西哥)的资源文件

专门

实际上我以前从未注意到这一点,但是当我去检查我的旧项目时,我看到它们都有基本文件,然后是特定于语言的文件。所以我只是更正它以遵循该约定,现在它可以工作了。

This is what ASP.NET documentation says about resources files.

It does not talk specifically about codebehind designer files generated on the fly but if you read the bolded text carefully, it is essentially saying that you need the base file without language specified and, given that, it makes sense that only this file will include autogenerated code.

"When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language and culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:

•WebResources.resx

The base resource file. This is the default (fallback) resource file.

•WebResources.es.resx

A resource file for Spanish.

•WebResources.es-mx.resx

A resource file for Spanish (Mexico) specifically.

•WebResources.de.resx

A resource file for German."

I actually have never noticed this before but when I went to check my old projects, I saw they all have the base file and then language specific ones. So I just corrected it to follow that convention and it works now.

番薯 2024-09-18 18:20:59

我遇到了同样的问题 - Designer.cs 文件对于某些 resx 文件不存在。

修复方法是设置 resx 文件的属性:

Build Action - Embedded Resource
Custom Tool  - PublicResXFileCodeGenerator

I had the same problem - Designer.cs file not being present for some resx files.

The fix was to set the properties for the resx files:

Build Action - Embedded Resource
Custom Tool  - PublicResXFileCodeGenerator
软糯酥胸 2024-09-18 18:20:59

如果我是你,我会:

创建一个新的 resx 文件;
打开旧的;
在旧的按ctrl+a;
在新的一处按ctrl+v;
保存新的;
删除旧的;
重命名新的:)

这应该可以快速解决问题。
您还可以通过单击“显示全部”按钮来检查 cs 文件是否未从文件中排除

If I were you, I would:

create a new resx file;
open the old one;
Press ctrl+a in the old one;
Press ctrl+v in the new one;
Save the new one;
Delete the old one;
Rename the new one :)

This should solve the problem quiet fast.
You could also check if the cs files are not excluded from the file by clicking the show all button

红焚 2024-09-18 18:20:59

很抱歉用这个来写评论。我的声誉实际上还不到 50 =( 但我认为这可能也很重要。

这指的是 Alvis 的回答:
你的解决方案成功了。但我还必须将基本设计器代码文件中属性的访问修饰符从内部修改为公共。否则,当我尝试访问 xaml 中的 resx 时,我会遇到 XmlParseExceptions。

编辑:
所以这里指的是C#/WPF。在 ASP.NET 中可能会有所不同

Sorry for using this to write a comment. My reputation actually is less than 50 =( but i think this might be important too.

This referes to Alvis' answer:
Your solution did the trick. But i had also to modify the access modifier of properties in the base designer code file from internal to public. Otherwise i got XmlParseExceptions when trying to access the resx in xaml.

Edit:
So this referes to C#/WPF. Could be different in ASP.NET

表情可笑 2024-09-18 18:20:59

我发现最好的方法是:

  • 创建默认文件:
    Resource1.resx
  • 让它创建:
    Resource1.Desinger.cs
  • 将其重命名为您想要的语言,例如Localize.en.resx

对我来说,任何其他方法都只是停止创建X.Designer。 cs 文件

I found the best way was to:

  • Create the file as the default:
    Resource1.resx
  • Let it create the:
    Resource1.Desinger.cs
  • Rename it to what language you want, e.g., Localize.en.resx

Any other way for me just stopped creating the X.Designer.cs files

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文