CS-Script - VSCode Extension (CS-Script.VSCode)
Execution, debugging and editing C# scripts (powered by CS-Script engine) that target .NET Core. A single C# file is all that is required to run the script.
This extension depends on another VSCode extension "ms-dotnettools.csharp". Thus if these extensions are installed but function incorrectly please log error reports at their corresponding web sites.
Note, the only dependency that you need to install to use this extension is .NET. The rest is included in the extension itself.
Though there are some strong benefits in managing CS-Script separatelly from the extension. A siple guide for that can be found here.
The scope of this page is limited to integration of CS-Script with VSCode and the documentation for CS-Script itself can be found at the locations below:
The extension implements its own Roslyn-based Intellisense functionality fully integrated with VSCode infrastructure. Though you can always opt to the VSCode built-in Intellisense engine OmniSharp. See Using CS-Script IntelliSense section for details.
The extension is powered by the CS-Script engine - popular Open Source script engine that delivers Python scripting experience but for C# syntax. CS-Script uses ECMA-compliant C# as a programming language and it can be hosted by applications or run standalone. CS-Script is already a core of the plugins for some other popular editors/IDEs:
The extension provides a thin layer of own functionality. Its primary responsibility is bringing together IntelliSense services, a full scale debugger (curtesy of "Mono Debug" team) and CS-Script seamless C# script execution. This page contains only a light overview of the extension functionality. The complete description can be found at the project Wiki.
Executing script outside of VSCode
The extension comes with the complete CS-Script package. You can find the location of the script engine
This is how you can execute the script from the command shell:
If CS-Ssript installed
You can also install CS-Script system wide. For Windows it is recommended to use Chocolaty (Windows equivalent of Linux apt-get). On Linux you can install Debian package. See instructions here: https://github.com/oleg-shilo/cs-script/wiki/CS-Script-on-Linux
Apart from the common VSCode C# functionality the extension brings CS-Script specific user activities in the picture.
Minimal set of dependencies (third-party extensions)
You will need the latest Mono from http://www.mono-project.com/download/ and the following VSCode extensions:
Note, you may need to add Mono to the system path manually if it didn't happen for you during the Mono installation.
Below are the road map highlights only. Some more detailed information are available in the last section of this document.
C# scripting with VSCode
CS-Script.VSCode allows convenient editing and execution of the C# code directly from the editor. A "C# script" is a file containing any ECMA-compliant C# code. While other C# based runtimes require C# code to be compiled into assemblies CS-Script allows direct C# execution by generating the assemblies on-fly. Thus you don't need to have any script specific configuration for executing your script. A single script file is fully sufficient as it contains everything that CS-Script needs to know to execute the script.
When your C# script depend on other (source code, assembly or NuGet package) C# modules you can express this in your code in a very simple way via
The following is the overview of the CS-Script functionality available with VS Code. The overview also highlights the major CS-Script featured:
Note: the most frequently used CS-Script command can also be accessed directly via toolbar buttons without using 'command palette':
Be aware that apart from allowing typical C# Intellisense this extension also provides C-Script specific code assistance features (mouse hover, go-to-definition and autocompletion) as well as the script project tree
While the extension is published on VSCode marketplace the latest unpublished[releases can be accesses on GitHub releases page.
Open the C# file and execute "run" command (Ctrl+F5):
Check for syntax errors
Open the C# file and execute "check" command (F7):
Open the C# file and execute "debug" command (Alt+F5):
Note: you can use standard VSCode debugging triggers (e.g. F5) if you load the script as a workspace. See 'Load as workspace' section.
Open the C# file and execute "print project" command (Alt+F7):
Using CS-Script IntelliSense
Open the C# file and start using normal intellisense triggers with CS-Script specific symbols: hover, go-to-definition, autocompletion, find references.
Please note that CS-Script IntelliSense is only enabled when no workspace loaded. This is done in order to avoid any interference with the standard VSCode Intellisense for workspaces.
The supported Intellisense features are:
"Find all references (classic)" is an alternative result representation of the standard VSCode "Find all references" for C#, TypeScript and VB.NET code (supported syntaxes can be extended). This presentation in conjunction with a single-click navigation is more consistent with the traditional Visual Studio experience:
Load as workspace
Open the C# file and execute "load project" command (ctrl+F7)
CS-Script and VSCode are following completely different project paradigm.
By default, when you just open a C#/VB.NET file the all development activities are handled by the CS-Script extension infrastructure. However sometimes you may prefer to use OmniSharp Intellisense. If it is the case you can open the script file and generate on-fly the all traditional project infrastructure - workspace (project file and folder). This can be achieved by executing the "load project" command (ctrl+F7).
VB.NET support is currently enabled for Windows+Mono hosting only. See the start section of this document about how to enable Mono hosting.
CS-Script supports VB.NET scripts as long as the underlying compiling services (Roslyn) support the syntax. Thus you can execute any VB.NET script by simply loading it into the editor and then executing it the same way as C# scripts.
The only limitation to that is that certain Intellisesne features may not work on Linux. And you will need to place break points programmatically (image above) since VSCode does not support VB syntax natively.
The extension comes with C# 7 support (via Roslyn, which is a part of .NET Core) enabled by default. However Roslyn has an unfortunate limitation - it is extremely heavy and slow on startup. Thus it can take ~3-5 seconds to do the first compilation of a script or an Intellisense request. Any further successive operations do not exhibit any delays.
A good indication of the extension being ready for Intellisense operations is the script project tree being populated and the status bar having "CS-Script ready" message at status bar. Note, the message stays only for 5 seconds:
Roslyn team did a good job by caching runtime instances of the compilers thus any consequent compilations will require only milliseconds to be accomplished. Unfortunately on Linux/Mono the same caching mechanism is not available so the compilation will consistently take up to 1.5 seconds (tested on VMWare Mint 18.1 4GB RAM on i7-5500U 2*2.40 GHz). Hopefully Roslyn team will extend runtime caching in the future releases of Mono.
Note, the Roslyn startup delay has no affect on script execution. CS-Script uses application level JIT compilation (similar to Python caching) that avoids compiling scripts if they are not changed since the last execution.