Home >Backend Development >C++ >How Can I Compile and Run C# Code from the Command Line?
C# command line compilation and execution
This article explains how to compile and run C# (.cs) files using the command line. This requires the C# compiler (csc.exe) included with the .NET Framework.
Compilation and execution under Windows system:
<code>c:\windows\Microsoft.NET\Framework\v3.5\bin\csc.exe /t:exe /out:MyApplication.exe MyApplication.cs</code>
Replace "MyApplication" with your desired executable name. The /t:exe
option specifies the output as an executable file, and the /out
option specifies the output file name.
<code>MyApplication</code>
You can also start "Visual Studio Command Prompt" in the "Visual Studio Tools" menu of the start menu, which will automatically configure the environment for command line compilation.
Compilation and execution under macOS system:
<code>$ csc /target:exe /out:MyApplication.exe MyApplication.cs</code>
<code>$ mono MyApplication.exe</code>
Tip: For more complex projects, it is recommended to use a build tool such as NAnt or MSBuild to create a complete build environment rather than just relying on a basic compiler.
The above is the detailed content of How Can I Compile and Run C# Code from the Command Line?. For more information, please follow other related articles on the PHP Chinese website!