简体   繁体   中英

What happens if I don't specify CompilerVersion with CSharpCodeProvider and why do most samples specify it?

Typical code samples using CSharpCodeProvider pass CompilerVersion parameter. Code from here :

var codeProvider =
    new CSharpCodeProvider(
       new Dictionary<String, String> { { "CompilerVersion", "v3.5" } });

I've tried to pass an empty dictionary and also tried to call the parameterless constructor of CSharpCodeProvider and the result is the same.

So what happens internally if I don't specify `CompilerVersion? Why do most samples specify it at all times?

The documentation states that it gets it from either the machine.config or the web.config specified in your framework config folder.

For example, my Framework64/config/web.config file contains this:

<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v4.0"/>
        <providerOption name="WarnAsError" value="false"/>
    </compiler>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM