Compile C # code extension at runtime

I have a system that compiles C # code at runtime. I would like the generated assemblies to be related to the system itself. Here is an example of the code I'm using:

CSharpCodeProvider provider = new CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v3.5" } }); CompilerParameters compilerparams = new CompilerParameters(); compilerparams.GenerateExecutable = false; compilerparams.GenerateInMemory = true; foreach (string name in linkedreferences) compilerparams.ReferencedAssemblies.Add(name + ".dll"); Assembly result = provider.CompileAssemblyFromFile(compilerparams, filename); 

What I would like to do is also add a link to the main compiler program, so a recently compiled extension can use library routines from the compiler program.

 Assembly entryasm = Assembly.GetEntryAssembly(); 

So the question is: how do I add a link to entryasm in the compiled build result?

+6
compiler-construction c #
source share
1 answer

Have you tried this?

  compilerparams.ReferencedAssemblies.Add(entryasm.Location); 
+3
source share

All Articles