如果我不使用CSharpCodeProvider指定CompilerVersion,会发生什么,为什么大多数示例都指定它? [英] What happens if I don't specify CompilerVersion with CSharpCodeProvider and why do most samples specify it?

查看:47
本文介绍了如果我不使用CSharpCodeProvider指定CompilerVersion,会发生什么,为什么大多数示例都指定它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 CSharpCodeProvider 的典型代码示例传递 CompilerVersion 参数.代码从此处:

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

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

我尝试传递一个空字典,还尝试调用 CSharpCodeProvider 的无参数构造函数,结果是相同的.

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

那么,如果我不指定`CompilerVersion,内部会发生什么?为什么大多数样本都始终指定它?

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

推荐答案

文档指出,它是从指定的 machine.config web.config 获取的在您的框架配置文件夹中.

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

例如,我的Framework64/config/web.config文件包含以下内容:

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>

这篇关于如果我不使用CSharpCodeProvider指定CompilerVersion,会发生什么,为什么大多数示例都指定它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆