Thursday 10 January 2013

ILMerge with .NET 4.0

ILMerge.exe will merge multiple DDLs into the same assembly, this has to be done sometimes, but I ran into a  problem up-scaling from .NET3.5 to .NET4.0



An exception occurred during merging:
  Unresolved assembly reference not allowed: System.ServiceModel.
     at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
     at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
     at System.Compiler.Ir2md.WriteTypeDefOrRefEncoded(BinaryWriter target, TypeNode type)
     at System.Compiler.Ir2md.WriteTypeSignature(BinaryWriter target, TypeNode type, Boolean instantiateGenericTypes)
     at System.Compiler.Ir2md.WriteTypeSignature(BinaryWriter target, TypeNode type, Boolean instantiateGenericTypes)
     at System.Compiler.Ir2md.GetBlobIndex(TypeNode type)
     at System.Compiler.Ir2md.GetTypeSpecIndex(TypeNode type)
     at System.Compiler.Ir2md.VisitReferencedType(TypeNode type)
     at System.Compiler.Ir2md.VisitClass(Class Class)
     at System.Compiler.Ir2md.VisitModule(Module module)
     at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
     at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
     at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
     at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
     at ILMerging.ILMerge.Merge()
     at ILMerging.ILMerge.Main(String[] args)



Issue

Seems that the ilmerge.exe tool can't reference the .NET4.0 assembles itself, you could add a path reference using the /lib option on the ilmerge.exe command script or use an imerge config file.


Solution 1: Use /Lib Option

ilmerge /lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" ...... bla bla.....

use when you want to use ilmerge on different builds of .NET; either different builds within the same solution or different builds within different solutions.

Solution 2: Config File

Locate this in the ilmerge program director eg C:\Program Files (x86)\Microsoft\ILMerge

    
   

use when you always want to use the same .NET framework across all builds.


References







No comments:

Post a Comment

Comments are welcome, but are moderated and may take a wee while before shown.