Click here to Skip to main content
13,864,346 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


34 bookmarked
Posted 16 Jun 2018
Licenced CPOL

Fast Scripting via C#

, 20 Jun 2018
Rate this:
Please Sign up or sign in to vote.
Quick and simple

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:

  1. 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):
  2. You can run code in Visual Studio. Select all text and click «Execute in interactive»

  3. By developer command prompt:

    And do this command:

    csi <path_to_csx>


  • +Written in C#
  • +Fast
  • +IDE pluses (IntelliSense, etc.)
  • - Requires csi.exe (by default in .NET Framework)

Using Libraries

Simple! Write:

#r "MyLib.dll"

in the beginning of *.csx file and copy DLLs to "bin" folder (create this folder near the your script file).


About CSI

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

Questioncurious about why you would use this rather than PowerShell Pin
BillWoodruff19-Jun-18 1:14
mveBillWoodruff19-Jun-18 1:14 
AnswerRe: curious about why you would use this rather than PowerShell Pin
Glebka2120-Jun-18 8:07
memberGlebka2120-Jun-18 8:07 
QuestionSource Code Pin
Alen Toma17-Jun-18 7:20
memberAlen Toma17-Jun-18 7:20 
AnswerRe: Source Code Pin
0x01AA17-Jun-18 9:51
professional0x01AA17-Jun-18 9:51 
GeneralRe: Source Code Pin
Alen Toma17-Jun-18 10:12
memberAlen Toma17-Jun-18 10:12 
QuestionGreat! Pin
0x01AA16-Jun-18 9:21
professional0x01AA16-Jun-18 9:21 
AnswerRe: Great! Pin
Glebka2116-Jun-18 23:34
memberGlebka2116-Jun-18 23:34 
GeneralRe: Great! Pin
0x01AA17-Jun-18 5:33
professional0x01AA17-Jun-18 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 20 Jun 2018
Article Copyright 2018 by Glebka21
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid