C# CSharpCodeProvider使用C语言版本7.1或更高版本

C# CSharpCodeProvider使用C语言版本7.1或更高版本,c#,.net,C#,.net,我有一个小的控制台项目,我试图将一些C#文件编译成.dll 代码如下所示: public Result CreateDll(string[] files, string assemblies, string toPath, string dllName) { if (!Directory.Exists(toPath)) Directory.CreateDirectory(toPath); using (var provid

我有一个小的控制台项目,我试图将一些C#文件编译成.dll

代码如下所示:

    public Result CreateDll(string[] files, string assemblies, string toPath, string dllName)
    {
        if (!Directory.Exists(toPath))
            Directory.CreateDirectory(toPath);

        using (var provider = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider(new CompilerSettings()))
        {
            var parameters = new CompilerParameters(assemblies)
            {
                GenerateInMemory = false,
                GenerateExecutable = false,
                OutputAssembly = $@"{toPath}\{dllName}.dll",
                IncludeDebugInformation = false,
                TreatWarningsAsErrors = true,
                CompilerOptions = "/unsafe /optimize"
            };

            CompilerResults results = provider.CompileAssemblyFromFile(parameters, files);
        }

        return Result.Success;
    }
    public abstract class BaseClass
{
    private string backendString;
    private string property;
    public string TestString => backendString;

    public string Property
    {
        get => property;
        set
        {
            if (value == default)
                return;
            property = value;
        }
    }
}
我试图编译的其中一个文件如下所示:

    public Result CreateDll(string[] files, string assemblies, string toPath, string dllName)
    {
        if (!Directory.Exists(toPath))
            Directory.CreateDirectory(toPath);

        using (var provider = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider(new CompilerSettings()))
        {
            var parameters = new CompilerParameters(assemblies)
            {
                GenerateInMemory = false,
                GenerateExecutable = false,
                OutputAssembly = $@"{toPath}\{dllName}.dll",
                IncludeDebugInformation = false,
                TreatWarningsAsErrors = true,
                CompilerOptions = "/unsafe /optimize"
            };

            CompilerResults results = provider.CompileAssemblyFromFile(parameters, files);
        }

        return Result.Success;
    }
    public abstract class BaseClass
{
    private string backendString;
    private string property;
    public string TestString => backendString;

    public string Property
    {
        get => property;
        set
        {
            if (value == default)
                return;
            property = value;
        }
    }
}
但我得到了这个错误:

功能“默认文字”在C#7.0中不可用。请使用7.1或更高版本的语言

如果我从
基类
中删除
*默认值*
,那么它不会抱怨。 如何更改此选项?

CompilerOptions=“/safe/optimize/langversion:7.1”

您有一个默认值为零的整数。关键是,默认值的使用让我觉得很糟糕,因为我使用了错误的c语言版本,这不是错误所说的。您是否从Visual Studio或其他验证代码的工具中收到错误?