ScriptCS empowers engineers to compose C# provisions utilizing a basic content tool. Aggregation is performed by Roslyn and bundle administration by Nuget.
Glenn Block, Project Manager of the Windows Azure SDK group, began ScriptCS, a side venture endeavoring to make C# a scripting dialect. While an engineer can utilize his C# learning to compose projects utilizing a straightforward word processor, the gathering is carried out in Roslyn, Microsoft's compiler-as-an administration. Scriptcs utilizes Nuget to run across bundles it relies on then transfers binaries. The Roslyn's r: sentence structure is utilized to include GAC or other DLL references.
In the event that a record hello.csx holds the following C# code line
Console.WriteLine("Hello World!");
then, running the command
scriptcs hello.csx
results in printing the Hello World!
string at the console.
There is no need for namespaces nor class definitions for this example, and there is no project, no
.obj
nor .exe
file generated. Roslyn does the compilation and ScriptCS executes the result.
Another more elaborate example is creating a Web API host:
using System; using System.IO; using System.Web.Http; using System.Web.Http.SelfHost; var address = "http://localhost:8080"; var conf = new HttpSelfHostConfiguration(new Uri(address)); conf.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var server = new HttpSelfHostServer(conf); server.OpenAsync().Wait(); Console.WriteLine("Listening..."); Console.ReadKey();
ScriptCS has a plug-in mechanism using the so called script packs as Block explains:
A script pack can offer up namespace imports, references, as well as objects which will be available to the script via the RequireAPI. The main goal of a script pack is to make authoring scripts using frameworks easier.As script packs can be installed via NuGet packages, they can easily be discovered and consumed.
Work is in progress to make ScriptCS work on Mono. Adding debugging capabilities to Roslyn is investigated. Sublime Text has created a plug-in for ScriptCS enabling syntax highlighting in a simple editor. Alternatively, Roslyn can be used to generate syntax highlighting in Visual Studio for .csx files.
Block lists the advantages of scripting C# based on his experience with Node.js:
- No projects, just script- One of the things I love about node.js is you don’t need a project. You can just jump in a folder start creating js files and go to town.
- No IDE requirement, you can just use a text editor.
- Packages over assemblies – In node, when you want to get something you use npm to download the packages.It’s super simple. You just have your app and your local node_modules folder and you are good to go.
- No compilation – This is a big one. With node, I just run node.exe and my app and it works. I don’t have to first create an executable to run, I just run.
All that is possible with Roslyn and NuGet. ScriptCS still deals with assemblies, but “but I don’t have to manage them individually, I just install packages.”
ScriptCS carries an Apache 2 license and it is currently not endorsed by Microsoft..
No comments:
Post a Comment