I checked some resource about roslyn,and i not found how to compile c# sources to executable with Roslyn.I can easily compile some .cs files to .exe using CodeDom:
/// <summary>
/// "anycpu" || "anycpu32bitpreferred" || "x86" || "x64" || "ARM" || "Itanium"
/// </summary>
public static string param = "anycpu";
public static string BCS(string[] sources,string[] libs,string outPath,bool exef)
{
var options = new Dictionary<string, string> {
{ "CompilerVersion", "v4.0.0" }
};
CSharpCodeProvider codeProvider = new CSharpCodeProvider(options);
CompilerParameters parameters = new CompilerParameters(libs);
parameters.GenerateExecutable = exef;
parameters.OutputAssembly = outPath;
parameters.CompilerOptions = "-platform:" + param;
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, sources);
if (results.Errors.Count > 0)
{
string errsText = "";
foreach (CompilerError CompErr in results.Errors)
{
errsText = "("+CompErr.ErrorNumber +
")Line " + CompErr.Line +
",Column "+CompErr.Column +
":"+CompErr.ErrorText + "" +
Environment.NewLine;
}
return errsText;
}
else
{
return "Success";
}
}
but problem of CodeDom - he can compile only c# with .NET Framework 4.0,but i need to compile c# files with 4.6.1 .NET Framework version.So,question: Can i compile some c# files(.cs) with 4.6.1 .NET Framework version using Roslyn Compiler?