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

微笑、不失礼 提交于 2019-12-13 14:35:15

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/19400394/what-happens-if-i-dont-specify-compilerversion-with-csharpcodeprovider-and-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!