Edit – if the question is: “How to create console application in Visual Studio?” – @emd provided good link: How to: Create a C# Console Application
Answer to: “How to create utility that takes CS file and run it as an executable?”
If you projects are all in single file (or group of CS files) without any non-trivial configuration than basic call to CSC.exe
will produce “.EXE” to run. You can easily wrap call to csc.exe
and execution of resulting “.exe” into “.CMD” file and (if you want to) associate that CMD with CS extension so entering CS file name will compile and execute code.
If project is more complicated – use MSBUID to build *.csproj file and than execute resulting EXE
For bonus points you can merge “.CS” and “.CMD” in one single file by wrapping CSC.exe
call in /**/
comments that are ignored by Windows CMD shell.
Note: CSC.exe
is installed as part of .Net Framework, so you don’t even need VS on the machine to use it. Location – %windir%\Microsoft.NET\Framework\v4.0.30319\csc.exe
solved making a utility to run C# code through command [closed]