我正在制作C#编译器代码,并且默认情况下,我的代码从应用程序启动路径执行exe文件。 如何通过参数更改exe位置
此代码在“ C:\ Users \ User \ Desktop \ CSharp编译器\ CSharp编译器\ bin \ Debug”中执行可执行文件
CSharpCodeProvider csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } });
CompilerParameters parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, ProjectName.Text + ".exe", true);
parameters.GenerateExecutable = true;
System.CodeDom.Compiler.TempFileCollection tfc = new TempFileCollection(Application.StartupPath, false);
CompilerResults cr = csc.CompileAssemblyFromSource(parameters, txtcode.Text);
if (cr.Errors.HasErrors)//this writes the errors in a richtextbox.
{
txtstatus.Text = txtstatus.Text + "\n\n";
cr.Errors.Cast<CompilerError>().ToList().ForEach(error => txtstatus.Text += error.ErrorText + "\r \n");
}
else
{
txtstatus.Text = txtstatus.Text + "\n\n No Errors \n ----Build scceeded----";
string build = "----Build scceeded----";
int index = txtstatus.Text.IndexOf("----Build scceeded----");
int length = build.Length;
txtstatus.Select(index, length);
txtstatus.SelectionColor = Color.LightGreen;
Process.Start(Application.StartupPath + "/" + ProjectName.Text + ".exe");
}
答案 0 :(得分:1)
要设置工作目录,您需要使用{。{1}}版本的Process.Start
它可以很简单
ProcessStartInfo
答案 1 :(得分:0)
我发现一种简单的方法是File.Move(Application.StartupPath + "/" + ProjectName.Text + ".exe",whereever);
可以移动文件,然后我将调用StartProcess。