C#
我现在把文件名读到listBox里面了,现在怎么才能调用编译器把我选择的.cs文件进行编译,并且把编译结果放到.txt文件里,先谢谢各位了

解决方案 »

  1.   

    先配置好csc.exe的Path环境变量,然后就可以这样写了:
    System.Diagnostics.Process.Start("cmd.exe","/c csc /t:library /r:System.dll /r:System.Web.dll /out:Test.dll Test.cs");
      

  2.   

    string cmdline = @"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc.exe  " + @"/out:" + csfileName + @".dll " + csfileName +  " >> " +  csfileName+ @".txt";System.Diagnostics.Process process = new System.Diagnostics.Process();process.StartInfo.FileName = "cmd.exe";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.CreateNoWindow = true;
    process.Start();
    process.StandardInput.WriteLine(cmdline);