I use CodeDom to compile dynamic c# code generated at runtime and execute it in memory. CodeDom reference external nuget library installed and it's located in bin folder.
The following code show how to reference the external library from binfoler:
CompilerParameters cp = new CompilerParameters();
//dll are in binFolder
var dll = Directory.EnumerateFiles(binFolder, "*.dll").ToArray();
cp.ReferencedAssemblies.AddRange(dll);
cp.GenerateExecutable = false;
cp.GenerateInMemory = true;
The program is working fine.
I want to use ILMerg to merge the exe and all dll files in one executable file so, i should modify the line:
var dll = Directory.EnumerateFiles(binFolder, "*.dll").ToArray();
to be:
// how to load the empeded dll by ILMerge to be passed to CompilerParameters cp
var dll = get_the_empeded_dll_by_ILMerge() ;
Can you help in implementing the function : get_the_empeded_dll_by_ILMerge()
The exe file that results from merging your original exe file a your dlls directly contains the types from your dlls. So you should be able to reference that exe file and it should behave as if you referenced all the dlls.
I don't know if there is some special way to check of some dll was merged to a loaded exe. One way you could do it is to check is some type from the dll is present in the exe, possibly a special marker type, e.g.:
class ThisIsDllFoo {}