Often, there is a need to quickly write a small script, with absolutely no desire to understand the syntax of bat-files or create a whole project for these cases.
There is one way to quickly write the script in C# without unnecessary movements.
First, create a new text file and change extension to *.csx:
Next, open file in your favourite code editor (I am using Visual Studio) and write the needed code:
You can run this code in several ways:
- Simplest - open file by csi.exe (%programfiles(x86)%\MSBuild\14.0\Bin\csi.exe or %programfiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn):
- You can run code in Visual Studio. Select all text and click «Execute in interactive»
- By developer command prompt:
And do this command:
- +Written in C#
- +IDE pluses (IntelliSense, etc.)
- - Requires csi.exe (by default in .NET Framework)
in the beginning of *.csx file and copy DLLs to "bin" folder (create this folder near the your script file).
Csi.exe is the Microsoft's command line RELP (read-evaluate-print-loop) tool.
It enables the use of C# as a scripting language by executing source code files directly. The source code IS the executable, so it is easy to make changes and there is no need to maintain a separate EXE file. CSI compiles source code "on the fly" and executes the resulting assembly seamlessly.
This tool uses Microsoft .NET Compiler Platform ("Roslyn") like a "C# Interactive" window in Visual Studio.