Microsoft just released .NET 10, and while it brings plenty of performance and language improvements, there’s one new trick that we’re really excited about — you can now run a C# file directly with:
dotnet run Program.cs
No projects. No .csproj. No setup.
Just write your C# file and run it like a script.
It might sound like a small thing, but for sysadmins, MSPs, and anyone managing servers or containers, this changes everything.
Before .NET 10, even the simplest program required creating a full project.
Now you can skip all that and just execute a single .cs file — it compiles and runs behind the scenes automatically.
You get the power and structure of C# with the convenience of PowerShell, Bash, or Python. It’s the best of both worlds — typed, fast, and cross-platform.
Here’s an example:
Console.WriteLine("Disk usage for C:\\");
foreach (var drive in System.IO.DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == "C:\\")
{
Console.WriteLine($"Total: {drive.TotalSize/1_000_000_000} GB");
Console.WriteLine($"Free : {drive.AvailableFreeSpace/1_000_000_000} GB");
}
}
Then simply run:
dotnet run MonitorDisk.cs
That’s it. Your script runs immediately.
You can even pull in NuGet packages with inline directives — no project file required:
#:package [email protected]
#:package [email protected]
using Serilog;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
Log.Information("Starting up Serilog demo...");
for (int i = 1; i <= 5; i++)
{
Log.Information("Iteration {Count}", i);
await Task.Delay(500);
}
Log.CloseAndFlush();
It’s clean, lightweight, and incredibly useful for quick jobs or one-off utilities.
The #:package directives are a new .NET 10 feature.
They tell the SDK to automatically pull NuGet packages when you run the file — no .csproj needed.
Everything after that is normal C# code using Serilog.
When you use dotnet run Program.cs on Windows, the SDK automatically creates a temporary working directory for your script under:
C:\Users\<username>\AppData\Local\Temp\dotnet\runfile\
That’s where it builds and executes your C# file behind the scenes.
The whole process is transparent — you don’t need to manage those files yourself, and they’re cleaned up automatically after each run.
This isn’t just a Windows thing — .NET 10 lets you use the shebang syntax on Linux and macOS to run your scripts just like Bash or Python.
You can write a script such as cleanup.cs like this:
#!/usr/bin/env dotnet run
Console.WriteLine("Cleaning up temp files...");
System.IO.Directory.GetFiles("/tmp")
.ToList()
.ForEach(System.IO.File.Delete);
Then make it executable:
chmod +x cleanup.cs
Now you can run it directly:
./cleanup.cs
That’s right — C# is officially a first-class scripting language on Linux now.
You can use it for cron jobs, maintenance scripts, container automation, or just quick admin tools, all using the same runtime and language you already use for your production apps.
For anyone running servers or hosting infrastructure, this is a major quality-of-life improvement.
You can use .NET 10’s scripting mode to:
Write quick utilities without spinning up full projects.
Stay entirely within the C# ecosystem — no need to jump to PowerShell or Bash.
Run the same scripts across Windows and Linux environments.
Use real NuGet packages in your scripts for logging, HTTP calls, JSON parsing, etc.
Convert any script into a proper project later with dotnet project convert Program.cs.
It’s fast, flexible, and fits right into the way MSPs and DevOps teams actually work.
In our own deployments we’re constantly writing small utilities for Active Directory health checks, backup cleanup, log analysis, and monitoring agents.
Before, that usually meant juggling PowerShell, Bash, or a quick Python script.
Now, we can do it all in C#, in a consistent runtime that already exists across our infrastructure.
The benefits are obvious:
- Unified language for automation, tools, and services.
- Cross-platform compatibility (Windows, Linux, containers).
- Long-term support from .NET 10 (LTS release = stability).
- No setup overhead for small scripts — write and run.
.NET 10 also ships with:
Big runtime performance improvements.
New C# 14 features (cleaner syntax, smarter lambdas).
Better container and tooling support (great for CI/CD pipelines).
Extended cryptography and post-quantum readiness.
But honestly, the single-file scripting support steals the show for us.
It’s the simplest change that unlocks a ton of practical new workflows — from quick server tasks to lightweight monitoring scripts.
The ability to type:
dotnet run script.cs
or even
./script.cs
and have a C# script just run feels like a quiet revolution.
For anyone who lives in Windows or Linux terminal windows all day, it’s one of those features that immediately makes life easier.
We’ll be using it heavily for our own Windows automation workflows — and it’s safe to say, C# just became a few people's favourite scripting language.
To find out more you can read the full release notes at released .NET 10