【问题标题】:Strong Named satellite assemblies using ResGen & AL with multiple resx / resources files使用具有多个 resx / 资源文件的 ResGen 和 AL 的强命名卫星程序集
【发布时间】:2012-03-29 16:24:34
【问题描述】:

无论出于何种原因,将多个 .resources 文件编译为单个附属程序集 (.dll) 时,资源将不会显示。编译单个资源将起作用。这是我使用的步骤...

  1. 我们有一个名为“报表查看器”的项目。此项目使用密钥 MySnKey.snk 通过 Properties > Signing > Sign the assembly 进行签名,选择一个强名称密钥文件:MySnKey.snk。
  2. 所有表单已更新为 Localizable = True
  3. 我们将所有 resx 文件处理为德语 de-DE。 resx 只有两个:MainForm.resx(项目根目录)和 Resources.resx(属性目录)。
  4. 我有一个包含 MainForm.de-DE.resx 和 Resources.de-DE.resx 的文件夹,它们是这些文件的翻译版本。
  5. 使用resgen,

    > "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" /compile Resources.de-DE.resx ReportViewer.Resources.de-DE.resources

    > "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" /compile MainForm.de-DE.resx ReportViewer.MainForm.de-DE.resources

这将创建适当的 .resources 文件。现在要链接,我使用 AL.exe:

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib /embed:ReportViewer.MainForm.de-DE.resources,ReportViewer.Resources.de-DE.resources /culture:de-DE /out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk

这将创建一个 ReportViewer.resources.dll 文件。如果我将其放入适当的子文件夹 de-DE>ReportViewer.resources.dll,则不走运。在 Program.cs 中,在调用 Run 之前,我有

Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");

如果,我只包含 MainForm 之类的

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib /embed:ReportViewer.MainForm.de-DE.resources /culture:de-DE /out:ReportViewer .resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk

显示相应的资源。

这让我很困惑。如果我将 .resx 文件添加到解决方案并进行编译,则输出 dll 可以正常工作,但我们试图避免将这些附属翻译带入解决方案。

没有生成错误并且创建了文件,所以我不知道我没有做什么。

非常感谢任何帮助。我比较了在运行 AL.exe 时将文件添加到输出文件的解决方案时输出 dll 之间的差异,它们都包含所有翻译。

编辑以包含解决方案,因为我无法回答问题

显然我对嵌入选项及其用法感到困惑。要正确使用 AL.exe 实用程序,我必须使用:

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" Resources.de-DE.resx ReportViewer.Properties.Resources.de-DE.resources

请注意,上面添加了 Properties 命名空间。我以前没有这样做过。

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" MainForm.de-DE.resx  ReportViewer.MainForm.de-DE.resources

请注意,由于 MainForm 只是在 ReportViewer 命名空间中,因此没有添加任何 Properties 命名空间。

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" 
/t:lib
/embed:ReportViewer.Properties.Resources.de-DE.resources
/embed:ReportViewer.MainForm.de-DE.resources 
/culture:de-DE /out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk

请注意,此行中有多个 /embed 项。我使用的是逗号,它重命名了内部结构,这不是我想要的。在文件之间提供空格会产生(看似)不相关的错误。请参阅 http://ondotnet.com/pub/a/dotnet/2002/10/14/local2.htm?page=2 了解精彩文章。

为了完整起见,编写此脚本的另一种方式是

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" Resources.de-DE.resx

注意这里没有重命名,输出只是 Resources.de-DE.resources

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ResGen" MainForm.de-DE.resx

注意这里没有重命名,输出只是 MainForm.de-DE.resources

> "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AL" /t:lib
/embed:Resources.de-DE.resources,ReportViewer.Properties.Resources.de-DE.resources
/embed:MainForm.de-DE.resources,ReportViewer.MainForm.de-DE.resources
/culture:de-DE
/out:ReportViewer.resources.dll /template:../../../Output/ReportViewer/bin/Debug/ReportViewer.exe /keyfile:../MySnKey.snk

请注意,重命名是在嵌入选项中的逗号之后完成的。第一个参数是文件名(.resources 文件),逗号后面是完全限定名(namespace.class.xx-XX.resources)。

【问题讨论】:

    标签: resources strongname satellite-assembly resgen al.exe


    【解决方案1】:

    在我知道我可以在这里回答之前就在帖子中回答了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 2023-03-25
      相关资源
      最近更新 更多