i wan wan to c#code c#。
到目前为止,我已经写了以下代码:
string cscPath = @"C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.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);
它有效且结果。
我与Visual Studio 2012一起工作。
实际上有可能已内置的C#代码编译C#代码,因此您无需遇到自己调用csc.exe的麻烦。请查看以下博客文章,其中解释了如何做:https://blogs.msdn.microsoft.com/abhinaba/2006/02/09/c-writing-extendable-applications-using-on-on-the-the-the-fly-compilation/
如果您想使用via Call csc.exe进行操作,则可以尝试直接调用csc.exe,而不是通过命令行:
string cscPath = @"C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe";
var cscArguments = "...";
Process.Start(cscPath, cscArguments);
为了找到错误,您可以从命令行运行完全相同的命令并检查那里的输出。那应该使您走上正确的轨道。