【问题标题】:How to use .resx resource files in C#.net?如何在 C#.net 中使用 .resx 资源文件?
【发布时间】:2014-06-04 16:50:52
【问题描述】:

我想使用资源文件来国际化我的 .net 应用程序。我正在我的登录页面的一个字段上尝试一个小测试:

 <td class="libelleCnx" id="texteMdp" runat="server">

 Mot de passe :</td>

我用 Visual Studio 创建了资源文件,它在 App_LocalData 中,名为 Login.resx 并包含以下资源:

 <data name="texteMotDePasse" xml:space="preserve">

 <value>Ze password</value>

 </data>

在我的登录类中,我尝试像这样使用该资源:

 protected ResourceManager manager = new ResourceManager("Login", typeof(Login).Assembly);

 protected void Page_Load(object sender, System.EventArgs e)

 {
 ...
 texteMdp.InnerText = manager.GetString("Login.texteMotDePasse");
 ...
 }

但我在尝试访问我的登录页面时收到 System.Resources.MissingManifestResourceException...

我可以使用 "texteMdp.InnerText = "stuff" " 修改该字段,所以我猜问题不在于该字段。我认为没有检测到资源文件......有人知道为什么吗?

谢谢!

【问题讨论】:

  • 检查这个问题,可能会有所帮助:stackoverflow.com/questions/1327692/…
  • ResourceManager 读取编译 .resx 文件,这些文件由 resgen.exe 转换为二进制 .resources 文件并嵌入到程序集清单中。你肯定在某个地方错过了一步:)
  • 谢谢,我试试看! resgen 是 Visual Studio 的功能吗?没看到文件有什么其他的关系,我再仔细看看
  • 所以,我用 resgen.exe 编译了我的文件,但现在找不到我的网页(我没有得到异常)。如果我删除编译的文件,它会再次“工作”。我想我必须将它嵌入到程序集中才能使其工作,但我尝试了 al commande ("al file /out:Login.dll") 但我收到 AL 1047 错误:导入文件时出错'... '——0x8013110e。如何将资源放入卫星中?
  • 最后,Hans Passant 解决方案奏效了,你只需要用 resgen.exe 编译它。我后来的问题只是因为该地方显然不能有 ressource.resource 和 resource.resx 文件,否则会出错。 (在我上次发表评论后,我尝试删除 resx 文件而不是资源,它工作得很好

标签: c# .net internationalization resources resourcemanager


【解决方案1】:

你可以直接使用 resourseName.StringName 例如:

Login.texteMotDePasse

【讨论】:

  • 我在某处读到过,但没有用:s。也许这是 Visual Studio 版本的问题?我在 2005 年工作。或者 Hans Passant 上面评论的内容是否适用于该技术?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-20
  • 1970-01-01
相关资源
最近更新 更多