相关文章推荐
考研的山寨机  ·  jQuery UI 1.10.4 on ...·  1 年前    · 
狂野的橡皮擦  ·  Private Keys issues ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

For .net 3.5 I pass v3.5 to CSharpCodeProvider, when I pass v4.5 to CSharpCodeProvider in a v4.5 app I get InvalidOperationException "Compiler executable file csc.exe cannot be found."

Anyone any idea what's going on here, what am I doing wrong?

Code to reproduce . . .

using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
namespace Console1
    class Program
        static void Main(string[] args)
            var options = new Dictionary<string, string>{{"CompilerVersion", "v4.5"}};
            var cs = new CSharpCodeProvider(options);
            var compilerParams = new CompilerParameters();
            var r = cs.CompileAssemblyFromSource(compilerParams , "namespace ns { class program { public static Main(string[] args) { System.Console.WriteLine(\"Hello world\"); } } }");
                I saw that question about th 4.5 beta, and decide to ask this, give  that something may have changed between the beta and final release.
– Binary Worrier
                Nov 6, 2012 at 15:43

This is by design, something you can see when you navigate to c:\windows\microsoft.net\framework with Windows Explorer. Note that you'll only see a subdirectory named v4.0.30319, there is no v4.5 subdirectory. Or in other words, .NET 4.5 is a true in-place update for version 4.0 and the C# v5 compiler replaces the v4 compiler.

You'll need to specify "v4.0".

Thanks, I assumed it should work the same way as the .net 3.0-3.5 update, but obviously not. Couldn't figure if it was "accidentally" working when targeting v4.0 from 4.5 and something was happening that I was unaware of. Thanks again for a definitive answer. – Binary Worrier Nov 6, 2012 at 16:45