ILMerge - Unresolved assembly reference not allowed: System.Core

ILMerge is a utility which allows you the merge multiple .NET assemblies into a single binary assembly more for convenient distribution. Recently we ran into problems when attempting to use ILMerge on a .NET 4 project. We received the error message:

**An exception occurred during merging:

Unresolved assembly reference not allowed: System.Core.   
at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)   
at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)   
at System.Compiler.Ir2md.VisitReferencedType(TypeNode type)   
at System.Compiler.Ir2md.GetMemberRefIndex(Member m)   
at System.Compiler.Ir2md.PopulateCustomAttributeTable()   
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)**

It turns out that this issue is caused by ILMerge.exe not being able to find the .NET 4 framework by default. The answer was ultimately found here. You either have to use the /lib option to point to your .NET 4 framework directory (e.g., "C:WindowsMicrosoft.NETFrameworkv4.0.30319" or "C:WindowsMicrosoft.NETFramework64v4.0.30319") or just use an ILMerge.exe.config file that looks like this:

    <startup useLegacyV2RuntimeActivationPolicy="true">
        <requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>

This was able to successfully resolve my issue.