Hey folks, I want to share a tip. Sublime Text is my favorite for quick scripts, text editing and doing other scripting things or anything which doesn’t require a whole IDE. I love the speed too much and it is super-fast. In the process, I found that you can run C# scripts too, right from inside the Sublime Text, like you can run JavaScript. This is what I will brief you about:
Sometime back, I wrote on configuring Sublime Text for JavaScript too. Here’s the link, if you want to learn:
Ok, let’s start. The process is simple. You need to have an executable file, which Sublime Text will use to execute the scripts.
For C#, we will use scriptcs. Like NodeJS can run JavaScript, scriptcs runs C#. You can write and execute an Application with only one line of code.
Steps to configure Sublime Text for executing C# codes
Steps to configure Sublime Text for executing C# codes
Step 1: Install scriptcs
In order to install scriptcs, you need to have chocolatey. Chocolatey is a package manager for Windows.
In order to install scriptcs, you need to have chocolatey. Chocolatey is a package manager for Windows.
You can install it in two ways:
- Using the command prompt (cmd.exe): Run the command, given below in the console:
- @powershell -NoProfile -ExecutionPolicy Bypass -Command “iex ((new-object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1’))” && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
- Using Powershell : Run either of the following commands
- iex ((new–object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1’))
- iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
There’s a chance you will get an error while running the script due to a Powershell Execution policy. By default, it is set to “Restricted” to prevent the harmful scripts from running. You can check the current execution policy by running “Get-ExecutionPolicy” command in Powershell.
If you encounter this error, set the execution policy to “RemoteSigned” and run the installation command again. Use the command given below:
- Set-ExecutionPolicy RemoteSigned
Make sure you start the Powershell console in Administrator mode, otherwise the change will not take place.
Read full article here on C# Corner:
http://www.c-sharpcorner.com/article/how-to-run-c-sharp-code-inside-sublime-text/
Happy learning 🙂