6

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));
}
Loman
  • 989
  • 6
  • 10
  • sounds like a Path Issue.. .net 3.5 assembly and 4.0 especially in terms of GAC for example do not share the same GAC check the path of where you have installed the .net 4.0 framework for starters... – MethodMan Dec 26 '11 at 00:51
  • .net4 is installed in C:\Windows\Microsoft.NET\Framework\v4.0.30319\ and .net3.5 is installed in C:\Windows\Microsoft.NET\Framework\v2.0.50727\ – Loman Dec 26 '11 at 01:06
  • Use "CompilerVersion" in the dictionary you pass to the constructor. http://msdn.microsoft.com/en-us/library/bb537926.aspx – Hans Passant Dec 26 '11 at 01:10
  • Hans thats what I'm doing. You have to scroll to the right in the example I posted to see it. – Loman Dec 26 '11 at 01:14
  • 3
    .NET 4.0 knows how to find the v2.0, v3.5 and v4.0 compilers. .NET 3.5 knows how to find the v2.0 and v3.5 compilers. But has never heard of a v4.0 version. – Hans Passant Dec 26 '11 at 16:15

1 Answers1

4

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

But not vice versa.

(I can be wrong).

abatishchev
  • 98,240
  • 88
  • 296
  • 433