简体   繁体   English

使用ILMerge合并.NET 3.5和.NET 2.0程序集时出现问题

[英]Issue when using ILMerge to merge .NET 3.5 & .NET 2.0 assemblies

When attempting to merge several assemblies in a VS Post Build I ran into the issue: 尝试在VS Post Build中合并多个程序集时遇到了问题:

ILMerge version 2.13.307.0
Copyright (C) Microsoft Corporation 2004-2006. All rights reserved.
ILMerge /out:Assembly.dll AssemblyA.dll AssemblyB.dll /targetplatform:v2,C:\Windows\Microsoft.NET\Framework\v3.5 /log:log.txt 
Set platform to 'v2', using directory 'C:\Windows\Microsoft.NET\Framework\v3.5' for mscorlib.dll
An exception occurred during merging:
Unable to cast object of type 'System.Compiler.Class' to type 'System.Compiler.Struct'.
   at System.Compiler.SystemTypes.Initialize(Boolean doNotLockFile, Boolean getDebugInfo, PostAssemblyLoadProcessor postAssemblyLoad)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

where AssemblyA is the current project output $(TargetFileName) and AssemblyB is a referenced assembly. AssemblyA是当前项目输出$(TargetFileName),AssemblyB是引用的程序集。

  1. AssemblyA => v3.5 AssemblyA => v3.5
  2. AssemblyB => v2.0 AssemblyB => v2.0

The weird thing is that when I change the command to use .NET 4 it works: 奇怪的是,当我更改命令以使用.NET 4时,它可以工作:

ILMerge /out:Assembly.dll AssemblyA.dll AssemblyB.dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /log:log.txt

Since I wish the merged assembly to be version 3.5 and not 4 how do I get the former command to work or how do I resolve this error? 由于我希望合并的程序集是版本3.5而不是4,如何让前一个命令工作或如何解决此错误?

using directory 'C:\\Windows\\Microsoft.NET\\Framework\\v3.5' for mscorlib.dll 使用目录'C:\\ Windows \\ Microsoft.NET \\ Framework \\ v3.5'为mscorlib.dll

Have a look, that directory doesn't contain mscorlib.dll. 看一下,该目录不包含mscorlib.dll。 There is not much there at all, the .NET Framework versions 3.0, 3.5 and 3.5SP1 do not include a new runtime version. 根本没有太多,.NET Framework版本3.0,3.5和3.5SP1不包含新的运行时版本。 The CLR, jitter and many of the base assemblies are still v2.0. CLR,抖动和许多基本组件仍然是v2.0。 The only difference in these later releases are added assemblies. 这些后续版本的唯一区别是添加了程序集。

So the required option is /targetplatform:v2,C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727 所以必需的选项是/targetplatform:v2,C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727

Fwiw, do be very, very careful when you target .NET 4.x, the c:\\windows\\microsoft.net directory is no longer the home directory for reference assemblies. Fwiw,当你以.NET 4.x为目标时,要非常非常小心,c:\\ windows \\ microsoft.net目录不再是引用程序集的主目录。 Now located in c:\\program files (x86)\\reference assemblies. 现在位于c:\\ program files(x86)\\ reference程序集中。 Getting this wrong can cause exceedingly hard to diagnose runtime errors when the machine has .NET 4.5+ installed. 当机器安装了.NET 4.5+时,出错可能会导致极难诊断运行时错误 And now it does matter which specific subdirectory you pick. 现在,您选择哪个特定的子目录确实很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM