Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to target the .net4 compiler from a .net3.5 app with a CSharpCodeProvider?

I'm trying to compile a .cs file using a CSharpCodeProvider from a .net 3.5 app and I want to target the .net4 compiler but I'm getting this error "Compiler executable file csc.exe cannot be found". I have .net4 installed. Below is the code that I'm using with some lines omitted for brevity. When I set CompilerVersion to "v3.5" I get no errors.

CompilerResults results = null;
using (CSharpCodeProvider provider = new CSharpCodeProvider(new Dictionary<string, string>() {{"CompilerVersion", "v4.0"},}))
{
    CompilerParameters options = new CompilerParameters(); 
    ...
    results = provider.CompileAssemblyFromFile(options, Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories));
}
like image 857
Loman Avatar asked Dec 26 '11 00:12

Loman


1 Answers

I think you can force using csc v3.5 from .NET 4.0.

But not vice versa.

(I can be wrong).

like image 116
abatishchev Avatar answered Nov 03 '22 02:11

abatishchev