RunCS: a scratchpad for C#
RunCS is a small desktop app for trying out C#. Code on the left, output on the right, and no project file in sight.
I love RunJS. When I want to check how a bit of JavaScript behaves, I open it, type, and the answer is right there beside the code. No project, no setup, no ceremony. I wanted exactly that for C#, and I couldn’t find it.
The options I looked at each missed in a different direction. NetPad is a capable tool, but it’s far more than I needed for a quick check. .NET Fiddle is the opposite: it’s web based and does too little, without the editor features and packages I’d want once a test grows past a few lines. I wanted something in between, a small desktop app that opens fast and does the common things well.
So I built RunCS, a desktop scratchpad for C#. You type code on the left, press Ctrl+Enter, and the output shows up on the right. No solution, no project file, no Program.cs boilerplate: just the code you wanted to try.
Built on file-based apps
.NET 10 added file-based apps: dotnet run hello.cs runs a single .cs file with no project around it. That’s what made RunCS small enough to be worth building. Every run is a plain dotnet run yourfile.cs, so anything a file-based app supports works in RunCS too, including NuGet packages pulled in with a directive at the top of the file:
#:package Humanizer@2.14.1
using Humanizer;
"RunCS_is_a_scratchpad".Humanize();
Because a script is just a .cs file, nothing is locked inside RunCS. Save it, and you can run it from a terminal, check it into a repo, or hand it to someone who has never heard of RunCS.
Seeing values without Console.WriteLine
The feature I use most: a top-level expression shows its value. A line like Add(2, 3); or just total; prints its result in the output pane, tagged with the line it came from. Assignments, void calls and un-awaited tasks stay quiet.
For values deeper in the code there are log points. Click the strip left of the line numbers (or press F9) to drop a diamond on a line, and on the next run that line reports what it did:
| Line | Shows |
|---|---|
var x = ...; or x = ...; |
the variable’s new value |
| an expression or call | its value |
return ...; |
the value returned |
if (...), while (...) |
whether the test was true |
foreach, for |
the loop variable, each time round |
a method with a { } body |
the arguments of each call |
a method written with => |
what it returns |
Log points never touch your script. RunCS compiles a temporary copy beside it with the logging added, and deletes the copy when the run ends.
An editor that knows C#
RunCS uses Roslyn for IntelliSense: a completion list as you type, parameter hints after ( and ,, type and documentation on hover, and error squiggles while you type. Types from a #:package line get completion too, once the package has been downloaded.
Compile errors show up in the editor rather than the output pane: a red badge beside the line number and a squiggle under the code. A crash marks the line it came from the same way, with its stack trace left in the output.
Packages and settings
Ctrl+P opens the Packages window: search every feed, double-click to add a package to the script, add a .nupkg from a link or a file, or add a GitHub Packages feed. Feeds live in RunCS’s own nuget.config, so your machine-wide NuGet sources are neither used nor changed, and the packages scripts pull in are kept in their own folder, apart from your global cache.
Ctrl+, opens Script settings: Native AOT, nullable reference types, implicit usings, unsafe code, warnings as errors, the C# language version, console or web project, and any other MSBuild property, plus the switch for showing top-level values. Each build setting is saved as a #:property or #:sdk line at the top of the file and hidden from the editor, so the settings travel with the script without cluttering it.
The little things
- Tabs, with Ctrl+T / Ctrl+W, and open tabs come back next time.
- New tabs live in
~/.runcsuntil you save them somewhere. - With several .NET SDKs installed, pick which one runs your scripts from the toolbar.
- One Run/Stop button: a green arrow while idle, a red square while running (Shift+F5 to stop).
A couple of honest limits: scripts run with your own permissions, with no sandbox, and Console.ReadLine() returns null because there’s no input box.
How it’s built
RunCS is about 5,000 lines of C#, and most of it is glue between a few good libraries.
- The window is Avalonia 11, so the same app runs on Windows, Linux and macOS. The editor is AvaloniaEdit, with TextMate grammars for syntax highlighting.
- IntelliSense comes from Roslyn. RunCS keeps the script in an in-memory Roslyn workspace, parsed with the option that accepts file-based apps’
#:lines, and asks it for completions, parameter hints, hover text and errors as you type. It points Roslyn at the reference assemblies of the SDK that will actually run the script, so what the editor tells you matches what the compiler will say. - Running is just the
dotnetCLI:dotnet run yourfile.cs, with output streamed back into the right-hand pane. When you pick an SDK, RunCS calls that SDK’s owndotnet.dlldirectly, which pins it no matter which onedotnetwould choose. - Values without
Console.WriteLinework by compiling a rewritten copy of the script. RunCS finds the top-level expressions and log points, wraps each one in a call to a small helper class appended to the end of the file, and writes the result between marker characters. The output pane picks the markers out of the stream, which can arrive split across chunks, and pins each value to its line. Every insertion goes inside an existing line, so line numbers in errors and stack traces still match your code. - Settings and packages are plain
#:property,#:sdkand#:packagelines in the file. RunCS hides the settings lines from the editor and edits them through the Script settings window, and restores packages through its ownnuget.configso your machine-wide NuGet setup is never touched.
Releases are built by GitHub Actions: changing the version in the .csproj and pushing to main builds Windows, Linux and macOS packages and attaches them to a new GitHub release.
Try it
RunCS needs the .NET 10 SDK. Downloads for Windows, Linux and macOS are on the releases page, and there’s more on the RunCS website.