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.
- Use C# Interactive Window for your coding experiment in Visual Studio 2015
- Command Line C# Interactive Script Execution 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](https://i0.wp.com/dailydotnettips.com/wp-content/uploads/2016/01/image66.png?resize=709%2C274&ssl=1)
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](https://i0.wp.com/dailydotnettips.com/wp-content/uploads/2016/01/image67.png?resize=506%2C204&ssl=1)
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](https://i0.wp.com/dailydotnettips.com/wp-content/uploads/2016/01/image68.png?resize=629%2C220&ssl=1)
Hope this helps !
Very nice article Abhijit. I’m really enjoying the series on Visual Studio 🙂
Thanks a lot mate. Glad to know.. Thanks for sharing them via your The Daily Six Pack series.. Have a great time !
Pingback: Visual Studio – Developer Top Ten for Jan 20th, 2016 - Dmitry Lyalin
Pingback: Using Command Window in Visual Studio
Pingback: Calling current project methods from C# Interactive Window in Visual Studio 2015 ?