예제 #1
0
        private void BuildAndRun_Click(object sender, RoutedEventArgs e)
        {
            Save_All();
            switch (Hensu.ProjectKinds)
            {
            case "kind:wpf":
                textBox1.Text = Build.wpfbuild();
                if (System.IO.File.Exists(Hensu.ProjectPath + @"\build\main.exe"))
                {
                    System.Diagnostics.Process.Start(Hensu.ProjectPath + @"\build\main.exe");
                }
                else
                {
                    MessageBox.Show("コンパイルエラーだよ!", "コンパイル情報", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case "kind:forms":
                //dllを探す


                //main.exe削除
                System.IO.File.Delete(Hensu.ProjectPath + @"\build\main.exe");
                System.IO.StreamWriter sw = new System.IO.StreamWriter(
                    @"now.txt",
                    false,
                    System.Text.Encoding.GetEncoding("shift_jis"));
                //TextBox1.Textの内容を書き込む
                sw.Write(Hensu.ProjectPath);
                //閉じる
                sw.Close();
                //System.Diagnostics.Process.Start("GUIconverter.exe ");
                //Processオブジェクトを作成
                System.Diagnostics.Process p = new System.Diagnostics.Process();

                //ComSpec(cmd.exe)のパスを取得して、FileNameプロパティに指定
                p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
                //出力を読み取れるようにする
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardInput  = false;
                //ウィンドウを表示しないようにする
                p.StartInfo.CreateNoWindow = true;
                //コマンドラインを指定("/c"は実行後閉じるために必要)
                p.StartInfo.Arguments = "/c GUIconverter.exe ";
                //起動
                p.Start();
                //プロセス終了まで待機する
                //WaitForExitはReadToEndの後である必要がある
                //(親プロセス、子プロセスでブロック防止のため)
                p.WaitForExit();
                p.Close();
                //
                //Processオブジェクトを作成
                System.Diagnostics.Process p1 = new System.Diagnostics.Process();

                //ComSpec(cmd.exe)のパスを取得して、FileNameプロパティに指定
                p1.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
                //出力を読み取れるようにする
                p1.StartInfo.UseShellExecute        = false;
                p1.StartInfo.RedirectStandardOutput = true;
                p1.StartInfo.RedirectStandardInput  = false;
                //ウィンドウを表示しないようにする
                p1.StartInfo.CreateNoWindow = true;
                //コマンドラインを指定("/c"は実行後閉じるために必要)
                if (Hensu.ProjectKinds == "kind:console")
                {
                    p1.StartInfo.Arguments = "/c cd /d" + Hensu.ProjectPath + @"\build" + @"& C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe *.cs";
                }
                else
                {
                    p1.StartInfo.Arguments = "/c cd /d" + Hensu.ProjectPath + @"\build" + @"& C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe  /target:winexe *.cs";
                }

                //
                //起動
                p1.Start();
                p1.WaitForExit();
                textBox1.Text = p1.StandardOutput.ReadToEnd();
                p1.Close();

                if (System.IO.File.Exists(Hensu.ProjectPath + @"\build\main.exe"))
                {
                    System.Diagnostics.Process.Start(Hensu.ProjectPath + @"\build\main.exe");
                }
                else
                {
                    MessageBox.Show("コンパイルエラーだよ!", "コンパイル情報", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;
            }
        }