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?
+1
A:
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.
Mehrdad Afshari
2009-01-26 13:55:10
A:
You can call the C# compiler in a command, and then catch the output.
Check here for more information on building from the command line.
Gerrie Schenck
2009-01-26 13:56:07
+7
A:
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
}
}
ShuggyCoUk
2009-01-26 13:57:45