havard-fjaer
asked on
Merging .NET assemblies using ILMerge
I am having trouble making ILMerge merge several assemblies into one. Even when I create a completely stripped down solution with three basic projects, the executable doesn't behave.
The ILMerge command runs without error:
ilmerge /target:winexe /out:ModuleMerging.exe Com.Fjaer.Test.ModuleMergi ng.Console .exe Com.Fjaer.Test.ModuleMergi ng.Library 1.dll Com.Fjaer.Test.ModuleMergi ng.Library 2.dll
However, when running the new exe, it crashes when it reach the line System.Console.ReadKey(); As it crashes immediately, I haven't been able to attach and debug the application at the point where it crashes, so I don't have an Exception that explains what happens.
Also, when I comment out the line the crashes, the rest of the code doesn't seem to run at all. When running the original exe the WriteLine statements are printed as expected:
In Class2
In Class1
In Program
... while the exe created by ILMerge prints nothing, but still exits without any exception or error code.
I'm theorizing that there must be something either about the security settings on the new assembly, or that the new assembly doesn't have a starting point telling it to run Main().
The test solution can be found here:
http://www.sharefile.org/showfile-1565/comfjaertestmodulemerging.zip
The ILMerge.exe command runs post-build.
ILMerge:
http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-B4AD-4EAE-87CF-B14AE6A939B0&displaylang=en
Any advice?
Thanks,
Håvard Fjær
www.fjær.no
The ILMerge command runs without error:
ilmerge /target:winexe /out:ModuleMerging.exe Com.Fjaer.Test.ModuleMergi
However, when running the new exe, it crashes when it reach the line System.Console.ReadKey(); As it crashes immediately, I haven't been able to attach and debug the application at the point where it crashes, so I don't have an Exception that explains what happens.
Also, when I comment out the line the crashes, the rest of the code doesn't seem to run at all. When running the original exe the WriteLine statements are printed as expected:
In Class2
In Class1
In Program
... while the exe created by ILMerge prints nothing, but still exits without any exception or error code.
I'm theorizing that there must be something either about the security settings on the new assembly, or that the new assembly doesn't have a starting point telling it to run Main().
The test solution can be found here:
http://www.sharefile.org/showfile-1565/comfjaertestmodulemerging.zip
The ILMerge.exe command runs post-build.
ILMerge:
http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-B4AD-4EAE-87CF-B14AE6A939B0&displaylang=en
Any advice?
Thanks,
Håvard Fjær
www.fjær.no
// Project: Com.Fjaer.Test.ModuleMerging.Console
// References:
// - System
// - Com.Fjaer.Test.ModuleMerging.Library1
using Com.Fjaer.Test.ModuleMerging.Library1;
namespace Com.Fjaer.Test.ModuleMerging.Console
{
internal class Program
{
private static void Main(string[] args)
{
var class1 = new Class1();
System.Console.WriteLine("In Program");
// System.Console.ReadKey();
}
}
}
// Project: Com.Fjaer.Test.ModuleMerging.Library1
// References:
// - System
// - Com.Fjaer.Test.ModuleMerging.Library2
using System;
using Com.Fjaer.Test.ModuleMerging.Library2;
namespace Com.Fjaer.Test.ModuleMerging.Library1
{
public class Class1
{
public Class1()
{
var class2 = new Class2();
Console.WriteLine("In Class1");
}
}
}
// Project: Com.Fjaer.Test.ModuleMerging.Library2
// References:
// - System
using System;
namespace Com.Fjaer.Test.ModuleMerging.Library2
{
public class Class2
{
public Class2()
{
Console.WriteLine("In Class2");
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help. As far as I know the merged assemblies should work just like the original assemblies, but I don't recall specifically testing reflection on merged assemblies.
ASKER
A quick question, as we are on the subject: Do you know if there are any common problems associated with merging assemblies? When reflecting attributes on assemblies, for instance. Are those individual attributes still part of the merged assemblies?