My code is this:
public static bool CompileClient(out string[] errors)
{
using (CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"))
{
CompilerParameters cp = new CompilerParameters
{
GenerateExecutable = true,
OutputAssembly = $"./hi.exe",
CompilerOptions = "/optimize",
TreatWarningsAsErrors = false
};
if (provider.Supports(GeneratorSupport.EntryPointMethod))
cp.MainClass = "Namespace.Program";
CompilerResults cr = provider.CompileAssemblyFromFile(cp, Directory.GetFiles("./Sourcecode/")); // Invoke compilation
if (cr.Errors.Count > 0)
{
List<string> _errors = new List<string>();
for (int i = 0; i < cr.Errors.Count; i++)
_errors.Add(cr.Errors[i].ToString());
errors = _errors.ToArray();
return false;
}
else
{
errors = null;
return true;
}
}
}
The .cs Files in /Sourcecode/ contain the following code:
$"Hello {name}"
When I compile the Files I get this Error: error CS1056: Unexpected character '$'.
Is there a way to fix the error without using string + string or string.Format()? maybe changing the version or something..?