Search code examples
c#csc

Run CSC.exe from command line using Batch File


I am using the following batch script code to compile c# code but what I see is a black window (csc.exe) flashes and I can not see the exe file created.

start /wait C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /out:aa.exe Program.cs
start aa.exe
pause

I want to create the file aa.exe at the same location as Program.cs

Basically what I want is to dynamically compile the code in Program.exe and run it. I am

using this following references:  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Net.Mail;

Solution

  • Rather than using start to launch the program, consider cmd. If you use cmd /K it should stay open after the command runs, giving you time to inspect the output.