I'm using this snippet
CSharpCodeProvider codeProvider =
new CSharpCodeProvider(
new Dictionary<String, String> { { "CompilerVersion", "v3.5" } });
for the 3.5 compiler for dynamic code compilation.
I'm assuming I should use "v4.0"
to switch to the 4.0 compiler?
We usually use a compiler with a graphical user interface, to compile our C program. This can also be done by using cmd. The command prompt has a set of steps we need to perform in order to execute our program without using a GUI compiler.
It is indeed v4.0
Besides specifying "v4.0", you will need to add the reference "Microsoft.CSharp.dll" in order to use the "dynamic" keyword.
var codeProvider = new Microsoft.CSharp.CSharpCodeProvider(
new Dictionary<string, string> { { "CompilerVersion", "v4.0" } });
var parameters = new System.CodeDom.Compiler.CompilerParameters
{
GenerateInMemory = true,
GenerateExecutable = false,
IncludeDebugInformation = true,
TreatWarningsAsErrors = false
};
// Here add more referenced assemblies
parameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
Don't forget to compile the solution using the Framework 4.0+.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With