C#执行命令行来编译其他C#代码

本文关键字:其他 代码 编译 执行 命令行 | 更新日期: 2023-09-27 18:21:59

有没有办法在c#程序中执行命令行并编译其他c#代码?

C#执行命令行来编译其他C#代码

假设要编译C#代码的计算机安装了C#编译器,这是可能的。

以下是访问命令行的一些示例代码

public void GenerateKeyFile(string path)
{
  string commandLine = " '"C:''Program Files''Microsoft Visual Studio 8''SDK''v2.0''Bin''sn.exe'" -k ";
  ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
  PSI.RedirectStandardInput = true;
  PSI.RedirectStandardOutput = true;
  PSI.RedirectStandardError = true;
  PSI.UseShellExecute = false;
  Process p = Process.Start(PSI);
  System.IO.StreamWriter SW = p.StandardInput;
  System.IO.StreamReader SR = p.StandardOutput;
  SW.WriteLine(commandLine + path);
  SW.Close();
}

以及如何从命令行使用C#编译器csc

这两个引用都是从Google 中的第一个结果中提取的