Build With ILMerge Error
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 c开发者_运维百科ommand ""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 ==========
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
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...).
精彩评论