Skip to content

A tool for .NET CLI to run C# sources as a script in the context of a project.

License

Notifications You must be signed in to change notification settings

aggieben/dotnet-script

Repository files navigation

This project was inspired by ScriptCs and Roslyn. I needed a way to execute a universal script as a part of the build process in .NET projects using the .NET Core tooling (.NET CLI). While there are a number of scripting languages available, most require at least to be installed.

When considering alternatives to writing multiple versions of scripts in order to cover the platforms I care about (Bash on Linux, MacOSX, and PowerShell on Windows) and resorting to tricks that would coincidentally work because we're lucky, it seemed like we could take advantage of the .NET platform, because we already have it (by definition).

The Roslyn scripting API is compatible with .NET Core, so it seemed reasonably doable to quickly throw together a dotnet-script tool to make this usable.

This is the result. Binary packages are available on https://www.myget.org/F/aggieben/api/v2 (v2 API) or https://www.myget.org/F/aggieben/api/v3/index.json (v3 API).

I'm calling this a "Beta 1" for now, in the spirit of the .NET Core betas, which means anything could change between now and the next commit (:trollface:).

To use this tool, reference it in your project.json "tools" section, like this:

{
  "dependencies": {},
  "frameworks": {},
  "tools": {
    "BitThicket.DotNet.ScriptTool": "0.1.0-beta-1-*"
  }
}

The only caveat here is that I'm distributing this as a portable binary, which means you have to have .NET Core installed on the machine where this is done. This will make the command available in your project directory(-ies) as dotnet script.

It takes one argument, the path of a script file. I'm using .csx for script files, so for me it would look like this:

dotnet script test.csx

I'm just using the Roslyn Scripting API, so presumably most of what it supports would be doable in a .csx script. Mark Michaelis wrote a pretty good description of what you can do in a script here.

About

A tool for .NET CLI to run C# sources as a script in the context of a project.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages