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

1

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));
}
Vociferate answered 26/12, 2011 at 0:41 Comment(5)
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...Pyroconductivity
.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\Vociferate
Use "CompilerVersion" in the dictionary you pass to the constructor. msdn.microsoft.com/en-us/library/bb537926.aspxAngola
Hans thats what I'm doing. You have to scroll to the right in the example I posted to see it.Vociferate
.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.Angola
O
4

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

But not vice versa.

(I can be wrong).

Overburdensome answered 26/12, 2011 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.