Executing C# Scripts from Command Line or C# Interactive Windows in Visual Studio

By | January 14, 2016

C# Script files is similar like other script files that contain a piece of C# code and can execute and returns the results.  As I said it is only piece of code – you really don’t have to have like a class  or method to get the result. The C# script file (CSX) file is  it’s own container and execute like a method. For Visual Studio, you can execute the CSX Script either using C# Interactive Window or CSI Command Line Window.

Before your proceed further, you must read following two posts to understand more about the new C# Interactive Window and the Command Line Interactive script engine for Visual Studio.

Consider you have following C# Script file named “MyScript.csx” which just print a series of number from a defined collection.

C# Script in VS Code

C# Script in VS Code

To run the script from the C# Interactive Window, write the following command and press enter.

#load "D:\Myscript.csx"

You will have following output :;

Execute Script from C# Interactive Window

Execute Script from C# Interactive Window

Similarly from the Command Prompt, open the Visual Studio Command Prompt and run the following command.

csi d:\MyScript.csx

Once the script loads and execute, you will have the following output.

Execute Script from Command Line Interactive Window

Execute Script from Command Line Interactive Window

Hope this helps !

5 thoughts on “Executing C# Scripts from Command Line or C# Interactive Windows in Visual Studio

  1. Abhijit Jana Post author

    Thanks a lot mate. Glad to know.. Thanks for sharing them via your The Daily Six Pack series.. Have a great time !

  2. Pingback: Visual Studio – Developer Top Ten for Jan 20th, 2016 - Dmitry Lyalin

  3. Pingback: Using Command Window in Visual Studio

  4. Pingback: Calling current project methods from C# Interactive Window in Visual Studio 2015 ?

Comments are closed.