i'm developing a simple C# Editor for one of my university courses and I need to send a .cs file to Compiler and collect errors (if they exist) and show them in my app. In other words i want to add a C# Compiler to my Editor. Is there anything like this for the debugger?
If you use the CodeDomProvider
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
// the compilation part
// change the parameters as you see fit
CompilerParameters cp = CreateCompilerParameters();
var options = new System.Collections.Generic.Dictionary<string, string>();
if (/* you want to use the 3.5 compiler*/)
{
options.Add("CompilerVersion", "v3.5");
}
var compiler = new CSharpCodeProvider(options);
CompilerResults cr = compiler.CompileAssemblyFromFile(cp,filename);
if (cr.Errors.HasErrors)
{
foreach (CompilerError err in cr.Errors)
{
// do something with the error/warning
}
}
Use the System.Diagnostics.Process
class to start a generic process and collect the I/O from standard input/output.
For this specific scenario, I suggest you look at Microsoft.CSharp.CSharpCodeProvider
class. It'll do the task for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With