构建时出现 ILMerge 错误

发布于 2024-09-06 23:35:03 字数 1562 浏览 7 评论 0原文

有人在使用 IlMerge 时遇到过此错误吗?我正在尝试使用 4.0 Framework 合并 .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):错误 MSB3073:命令“”C:\Program Files (x86)\Microsoft\Ilmerge\Ilmerge.exe”/log /lib :"..\Libraries" /targetplatform:v4 /internalize:./.exited with code 1...

...

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

Has anyone had this error with IlMerge? I am trying to merge a few assemblies for a .NET project using the 4.0 Framework.

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

Set platform to 'v4', using directory 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727..\v4.0.20107' for mscorlib.dll

An exception occurred during merging:

Object reference not set to an instance of an object.

 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...

...

========== Rebuild All: 3 succeeded, 1 failed, 0 skipped ==========

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

郁金香雨 2024-09-13 23:35:03

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

.\ILMerge /out:Merged.dll /targetplatform:'v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319' .\Assembly1.dll .\Assembly2.dll

Include the path to the 4.0 Framework in your targetplatform and be sure to use quotes. For example, from PowerShell:

.\ILMerge /out:Merged.dll /targetplatform:'v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319' .\Assembly1.dll .\Assembly2.dll
世界等同你 2024-09-13 23:35:03

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

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

这个问题的根本原因是 4.0 之后的框架已经是“就地升级”,一些依赖项围绕核心库移动(详细讨论请参见:http://www.hurryupandwait。 io/blog/what-you-should-know-about-running-ilmerge-on-net-4-5-assemblies-targeting-net-4-0)。总而言之,您可能有多个版本的 ilmerge 可用,但只有最新版本才能保证能够准确地重新整理您的依赖项,以便在运行时找到东西,而不是指定的文件丢失了,它是指向底层调用的指针。

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

I'm answering this old question because I didn't find an answer to my own related question on Stack Overflow and it might help someone else. In my case, I was trying to touch and rebuild an old solution in VS2013 to fix a glitch in the installer (not recognizing IIS10 as newer than IIS4).

The merge operation was giving me a "The system cannot find the file specified Error Code 0x80070002" and if you ignored the error and installed the application it would get stuck with a runtime exception. Of course "the file specified" was right there in the build folder.

The root cause of this problem is that frameworks after 4.0 have been an "in place upgrade" with some of the dependencies moving around the core libraries (for a long discussion see: http://www.hurryupandwait.io/blog/what-you-should-know-about-running-ilmerge-on-net-4-5-assemblies-targeting-net-4-0). The long and the short of it is that you may have several versions of ilmerge available to you but only the most recent is guaranteed to be able to accurately unshuffle your dependencies so that things will be found at runtime, it's not the files specified that are missing, it's the pointers to the underlying calls.

The solution in my case was to find a version of ilmerge retrieved from NuGet and to reference that from my old solution while leaving everything else as is. (I should have known this, but I was in a hurry/not thinking straight and the error message is misleading...).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文