1

I have a small console project where I'm trying to compile some C# files into a .dll.

The code looks like:

    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;
    }

One of the files I'm trying to compile looks like:

    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;
        }
    }
}

But I get this error:

Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.

If I remove the *default* from BaseClass, then it does not complain. How do I change this?

3
  • You have an integer which default value is zero. Commented Mar 27, 2020 at 13:26
  • So the point is, the usage of default makes it blow up for me, as im using a wrong c# language version Commented Mar 27, 2020 at 13:28
  • Isn't that what the error states. Are you getting error from Visual Studio or another tool that is verifying the code? Commented Mar 27, 2020 at 13:32

1 Answer 1

2
CompilerOptions = "/unsafe /optimize /langversion:7.1"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.