c# - ILMerge + 本地化资源程序集

标签 c# winforms .net-2.0 ilmerge

我正在使用 ILMerge 从包含 1 个 exe 和 2 个资源 dll 的项目中创建单个程序集应用程序:

  • \bin\Debug\test.exe
  • \bin\Debug\nl-BE\test.resources.dll
  • \bin\Debug\fr-FR\test.resources.dll

这是一个简单的测试项目,只有 1 个表单 (Form1.cs),所以没什么特别的。 我的目标是创建一个具有工作资源管理器的单个程序集应用程序(我已阅读 ILMerge and localized resource assembliesSingle-assembly multi-language Windows Forms deployment (ILMerge and satellite assemblies / localization) - possible? 以获取有关如何执行此操作的信息)。

编译项目后,我使用以下命令行参数运行 ILMerge:

ilmerge /log:test.txt /target:winexe /copyattrs /allowdup /out:test_merged.exe 
"C:\projectdir\bin\Debug\test.exe" "C:\projectdir\bin\Debug\fr-FR\test.resources.dll" 
"C:\projectdir\bin\Debug\nl-BE\test.resources.dll"

如果我用 Reflector 检查合并程序集的内容,我会在资源树节点下看到以下内容:

  • test.Form1.fr-FR.resources
  • test.Form1.fr-FR.resources
  • test.Form1.resources
  • 测试.Properties.Resources.resources

我有 2 倍的 fr-FR 资源,而不是 fr-FR 和 nl-BE 资源。这是因为资源 dll 具有相同的名称吗?结果是我只能在运行时获取fr-FR资源。

有什么想法吗?

更新(日志文件内容): (注意:二进制文件以“loc_”为前缀,为了清楚起见,我在之前的帖子中将它们省略了)

ILMerge version 2.10.526.0
Copyright (C) Microsoft Corporation 2004-2006. All rights reserved.
ILMerge /log:loc_test.txt /target:winexe /copyattrs /allowdup /out:loc_test_merged.exe c:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\loc_test.exe C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\fr-FR\loc_test.resources.dll C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\nl-BE\loc_test.resources.dll 
Set platform to 'v2', using directory 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\..\v2.0.50727' for mscorlib.dll
Running on Microsoft (R) .NET Framework v2.0.50727
mscorlib.dll version = 2.0.0.0
The list of input assemblies is:
    c:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\loc_test.exe
    C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\fr-FR\loc_test.resources.dll
    C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\nl-BE\loc_test.resources.dll
Trying to read assembly from the file 'c:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\loc_test.exe'.
    Successfully read in assembly.
    There were no errors reported in loc_test's metadata.
Trying to read assembly from the file 'C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\fr-FR\loc_test.resources.dll'.
Can not find PDB file. Debug info will not be available for assembly 'C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\fr-FR\loc_test.resources.dll'.
    Successfully read in assembly.
    There were no errors reported in loc_test.resources's metadata.
Trying to read assembly from the file 'C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\nl-BE\loc_test.resources.dll'.
Can not find PDB file. Debug info will not be available for assembly 'C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\nl-BE\loc_test.resources.dll'.
    Successfully read in assembly.
    There were no errors reported in loc_test.resources's metadata.
Checking to see that all of the input assemblies have a compatible PeKind.
    loc_test.PeKind = ILonly
    loc_test.resources.PeKind = ILonly
    loc_test.resources.PeKind = ILonly
All input assemblies have a compatible PeKind value.
Merging assembly 'loc_test' into target assembly.
Merging assembly 'loc_test.resources' into target assembly.
Merging assembly 'loc_test.resources' into target assembly.
Merging assembly-level attributes from assembly 'loc_test' into target assembly.
Copying 2 Win32 Resources from assembly 'loc_test' into target assembly.
Transferring entry point 'loc_test.Program.Main' from assembly 'loc_test' to assembly 'loc_test_merged'.
    There were no errors reported in the target assembly's metadata.
ILMerge: Writing target assembly 'loc_test_merged.exe'.
AssemblyResolver: Assembly 'System' is referencing assembly 'System.Configuration'.
    AssemblyResolver: Attempting referencing assembly's directory.
Can not find PDB file. Debug info will not be available for assembly 'System.Configuration'.
Resolved assembly reference 'System.Configuration' to 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Configuration.dll'. (Used referencing Module's directory.)
Location for referenced assembly 'System.Windows.Forms' is 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll'
    There were no errors reported in  System.Windows.Forms's metadata.
Location for referenced assembly 'System' is 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll'
    There were no errors reported in  System's metadata.
Location for referenced assembly 'mscorlib' is 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll'
    There were no errors reported in  mscorlib's metadata.
Location for referenced assembly 'System.Drawing' is 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll'
    There were no errors reported in  System.Drawing's metadata.
ILMerge: Done.

更新:http://www.filedropper.com/loctest 上提供了包含项目代码的 zip 文件

更新:信不信由你,但如果我分两步执行 ILMerge,它就会成功!

ilmerge /log:loc_test.txt /target:winexe /copyattrs /allowdup /out:loc_test_merged.exe "c:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\loc_test.exe" "C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\fr-FR\loc_test.resources.dll"

ilmerge /log:loc_test.txt /target:winexe /copyattrs /allowdup /out:loc_test_merged_2.exe loc_test_merged.exe "C:\Users\<user>\Documents\Visual Studio 2008\Projects\loc_test\loc_test\bin\Debug\nl-BE\loc_test.resources.dll"

这可能是什么原因?

谢谢, 贾尼克

最佳答案

虽然我不知道 ILMerge 分两步正确集成程序集的原因的详细信息,但这似乎是目前唯一的解决方案。检查我在问题中的最后修改,看看我是如何做到的。

我仍然很好奇为什么它不能一步完成......

关于c# - ILMerge + 本地化资源程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389037/

相关文章:

c# - c++和c#之间通过管道进行通信

c# - 如何在Asp.Net中打印大量图像?

c# - 如何中断 Console.ReadLine

c# - 从 DataGridView 中删除列

c# - 为什么 ControlCollection 不抛出 InvalidOperationException?

c# - 如何从 XmlReader 构建 XmlNode

c# - 如何从整数值中获取月份名称?

c# - 如何在 Java swings GUI 应用程序中访问和使用 C# dll

.net - 在 WinForms 中使用自定义 WPF 控件

.net - basicHttpBinding 是将 .Net 2.0 客户端连接到 WCF 服务的唯一选项吗?