【发布时间】:2017-02-26 18:50:12
【问题描述】:
我想从另一个用 C# 编写的 C# 代码编译。
到目前为止,我已经编写了以下代码:
string cscPath = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe";
string command = "/c \"" + cscPath + "\" /out:\"" + resultsFilePath
+ "\" /reference:\"" + dllPath
+ "\" \"" + csFilePath + "\" > \"" + resultsPath + "\\result.txt\"";
Process.Start("cmd.exe", command );
result.txt 文件未创建,我不知道如何检查错误信息。
如果我运行这样的事情:
string command = "/c echo something > \"" + resultsPath + "\\result.txt\"";
Process.Start("cmd.exe", command);
它有效,并且 result.txt 包含“某物”字样。
我使用 Visual Studio 2012。
【问题讨论】:
-
您是否尝试将
command打印到控制台并在CMD 中手动执行?也许你会发现它甚至不是你之前所期望的命令。 -
是的。我复制了命令字符串(在调试过程中)并在命令窗口中手动执行。它有效。