ReferencedAssemblies from merged exe file
-
Saturday, September 01, 2012 9:18 PM
Hello,
I have an issue in C# and I could not find an answer anywhere. I have an solution with three projects - one WPF application and two dlls (i. e. three assemblies). I wanted to merge those into one exe file after build process and I used Costura utility (https://github.com/SimonCropp/Costura) - because IL Merge does not work properly with WPF.
In the one of the libraries I have a piece of code for runtime compilation and I need to reference those two library assemblies, so I need to do something like that:
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("assembly1.dll");
parameters.ReferencedAssemblies.Add("assembly2.dll");But it does not work properly, because they are a part of the merged exe file. Is there any way how to reference those assemblies to the C# runtime compiler, when they are a part of the merged exe file?
Thank you for your answer.
John
All Replies
-
Tuesday, September 04, 2012 4:32 PMModerator
I'm not sure exactly how Costura managed the merged IL, but you should be able to just add a reference to the .exe file:
CompilerParameters parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add("merged.exe");
Since the two assemblies were merged into the main .exe, the types should all be defined within that new assembly.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Tuesday, September 04, 2012 4:55 PM
Thank you for your answer, but this does not work with Costura. The C# compiler throws an exception and says that it can not find the definition for a class I use in the code.
When I try to get the name of the assembly where the type I need is defined, I normally get the name of the original assembly (not the merged one), so it seems, that there are physically still three assemblies, but they behave like one.
I tried it with this piece of code:
Assembly a = Assembly.GetAssembly(typeof(Component)); System.Windows.MessageBox.Show(a.Location + a.GetName().Name);Bad thing is, that a.Location contains an empty string, so I have no idea how to reference that nested assembly.
I will be grateful for any help.
Thank you.
-
Tuesday, September 04, 2012 5:03 PMModerator
I just looked at Costura - This is actually going to be quite difficult.
The problem is that Costura doesn't "merge" the assemblies directly; it makes them resources of the main assembly, and unpacks on the fly. You'd have to extract out those assembly resources, and save them to disk somewhere in order to add them as references. I woudl recommend not merging, as this will just make your life simpler in this case.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Marked As Answer by honzaskvaril Tuesday, September 04, 2012 5:12 PM
-
Tuesday, September 04, 2012 5:12 PM
Ok, I will do it this way. Thank you very much for your help.
Besh regards,
John

