Iris Classon
Iris Classon - In Love with Code

File-Based Apps in .NET 10

One of my favourite improvements in recent .NET versions, and something that feels properly usable in .NET 10, is file-based apps. You can create a single .cs file and run it directly. No project file, no solution, no folder structure, just code.

dotnet run hello.cs

That’s it.

What it looks like

A minimal file-based app is just a .cs file with top-level statements:

var name = args.FirstOrDefault() ?? "world";
Console.WriteLine($"Hello, {name}!");

Save it as hello.cs, run dotnet run hello.cs, and you are done.

If you need a NuGet package, you can reference it at the top of the file. For example, using System.CommandLine to handle arguments:

#:package System.CommandLine@2.0.0

using System.CommandLine;

var nameOption = new Option<string>("--name", () => "world");

var root = new RootCommand
{
    nameOption
};

root.SetHandler((name) =>
{
    Console.WriteLine($"Hello, {name}!");
}, nameOption);

await root.InvokeAsync(args);

There is no .csproj to manage and no explicit restore step. The tooling takes care of it in the background.

Why it matters

C# has always been a strong choice for small tools and automation, but the setup got in the way. Before writing any actual logic, you had already created a project, picked a template, and committed to a structure.

Languages like Python and JavaScript never had that overhead. A script is just a file. You write it and run it.

File-based apps move C# much closer to that experience. It becomes practical to reach for C# for quick scripts, small utilities, or experiments without switching languages or setting up a project. That lowers the barrier both for experienced developers who want speed and for beginners who just want to try something without understanding the full project system first.

Key benefits include

Reduced boilerplate for simple applications You can go from idea to running code without scaffolding a project. For small utilities, that removes most of the friction that used to come before the actual work.

Self-contained source files with embedded configuration Dependencies and basic configuration can live alongside your code. That makes the file portable and easier to share, since everything you need is defined in one place.

Works well with modern publishing options File-based apps fit naturally with things like single-file publishing and Native AOT. If you decide a script should become something you distribute, you are already close to a publishable shape.

Easy path to CLI tools A small script can evolve into a proper command-line tool without a big rewrite. You can start simple and grow into a more structured project when it makes sense, instead of committing upfront.

When to use it

This is not a replacement for regular projects. As soon as you need multiple files, tests, or anything resembling real application structure, you still want a project.

But for automation scripts, quick data processing, trying out an API, or teaching someone the basics of C#, a single file is often exactly the right tool.

Comments

Leave a comment below, or by email.

Last modified on 2026-03-01

comments powered by Disqus