4

有人对 IlMerge 有此错误吗?我正在尝试使用 4.0 框架为 .NET 项目合并一些程序集。

ILMerge /log /lib:..\Libraries /targetplatform:v4 /internalize:..\SolutionFiles\CJCommon.exclude /ndebug /out:bin\Release\Common.dll obj\Release\Common.dll C:\Development\CJCommon \Libraries\FluentNHibernate.dll C:\Development\CJCommon\Libraries\HibernatingRhinos.Profiler.Appender.dll C:\Development\CJCommon\Libraries\Iesi.Collections.dll C:\Development\CJCommon\Libraries\log4net.dll C: \Development\CJCommon\Libraries\Microsoft.Practices.ServiceLocation.dll C:\Development\CJCommon\Libraries\NHibernate.ByteCode.Castle.dll C:\Development\CJCommon\Libraries\NHibernate.dll C:\Development\CJCommon\Libraries \NHibernate.Linq.dll C:\Development\CJCommon\Libraries\StructureMap.dll

将平台设置为“v4”,使用目录“C:\Windows\Microsoft.NET\Framework64\v2.0.50727..\v4.0.20107”作为 mscorlib.dll

合并时发生异常:

你调用的对象是空的。

 at System.Compiler.CoreSystemTypes.GetSystemAssembly(Boolean doNotLockFile, Boolean getDebugInfo)
 at System.Compiler.CoreSystemTypes.Initialize(Boolean doNotLockFile, Boolean getDebugInfo)
 at System.Compiler.SystemTypes.Initialize(Boolean doNotLockFile, Boolean getDebugInfo)
 at ILMerging.ILMerge.Merge()
 at ILMerging.ILMerge.Main(String[] args)

C:\Program Files (x86)\MSBuild\Ilmerge.CSharp.targets(8,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft\Ilmerge\Ilmerge.exe" /log /lib :"..\Libraries" /targetplatform:v4 /internalize:./.exited with code 1...

...

==========全部重建:3成功,1失败,0跳过==========

4

2 回答 2

11

在目标平台中包含 4.0 框架的路径,并确保使用引号。例如,从 PowerShell:

.\ILMerge /out:Merged.dll /targetplatform:'v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319' .\Assembly1.dll .\Assembly2.dll
于 2010-07-08T19:50:31.103 回答
0

我正在回答这个老问题,因为我没有在 Stack Overflow 上找到我自己的相关问题的答案,它可能对其他人有所帮助。就我而言,我试图在 VS2013 中修改并重建一个旧的解决方案,以修复安装程序中的一个故障(不将 IIS10 识别为比 IIS4 更新)。

合并操作给了我一个“系统找不到指定的错误代码 0x80070002 的文件”,如果您忽略了该错误并安装了应用程序,它将陷入运行时异常。当然,“指定的文件”就在构建文件夹中。

这个问题的根本原因是 4.0 之后的框架是“就地升级”,其中一些依赖项围绕核心库移动(关于长时间的讨论,请参见:http ://www.hurryupandwait.io/blog/what-你应该知道关于运行 ilmerge-on-net-4-5-assemblies-targeting-net-4-0)。总而言之,您可能有多个版本的 ilmerge 可供您使用,但只有最新版本才能保证能够准确地解散您的依赖项,以便在运行时找到东西,而不是指定的文件是缺少,它是指向底层调用的指针。

在我的情况下,解决方案是找到从 NuGet 检索的 ilmerge 版本,并从我的旧解决方案中引用它,同时保留其他所有内容。(我应该知道这一点,但我很着急/没有直接思考,并且错误消息具有误导性......)。

于 2020-11-10T18:42:00.813 回答