dotnet run hello.cs — C# Finally Got Its "Python Moment" in .NET 10
How File-Based Apps in C# 14 & .NET 10 kill the boilerplate and bring scripting-speed prototyping to the world’s most powerful typed…
dotnet run hello.cs — C# Finally Got Its "Python Moment" in .NET 10
How File-Based Apps in C# 14 & .NET 10 kill the boilerplate and bring scripting-speed prototyping to the world’s most powerful typed language

Introduction: The Problem Every C# Developer Knows
You have a ten-line idea. A quick API test. A CSV converter. A random data generator. Something you’d knock out in 30 seconds in Python.
But in C#? You open Visual Studio, wait for it to load, click File → New Project, pick a template, name it TestProject47, choose a location, wait for scaffolding to complete... and by then you've forgotten what you were trying to test.
Developers have lost more coding momentum to project scaffolding than they’d like to admit.
.NET 10 and C# 14 just fixed this. The feature is called File-Based Apps, and it changes everything about how you prototype in C#.
What Are File-Based Apps?
File-based apps, introduced in .NET 10, allow you to write and run a C# application starting from a single .cs file, without creating a project or a solution. You can execute it directly using the .NET CLI, keeping the focus on code instead of configuration.
The command is beautifully simple:
dotnet run app.cs
That’s it. No .csproj. No solution file. No bin/ folder cluttering your workspace. Think of it like running a Python script — just write code and execute it.
Developers no longer need to create a project file or scaffold an entire application to test a snippet, run a quick script, or experiment with an idea.
How It Works Under the Hood
You don’t get magic — you get smart automation. When you run a file-based app, the .NET CLI automatically creates a virtual project in memory, resolves dependencies, compiles the code, and executes it — all without you defining a project structure upfront. From a developer perspective, this means you can treat a .cs file as a self-contained application, not just as source code.
The first run takes a moment because the SDK compiles the code. Subsequent runs are faster thanks to caching.
Your simplest possible file-based app:
// hello.cs
Console.WriteLine("Hello from .NET 10!");
Run it:
dotnet run hello.cs
# Hello from .NET 10!
No using System;. No class Program. No static void Main. The compiler generates all that ceremony for you — it creates a Program class, an entry point method, handles async if needed, and exposes args as a magic variable.
The #: Directive System — Your New Best Friend
This is where file-based apps go from “cute trick” to genuinely powerful. With .NET 10 Preview 4, file-based apps support a set of powerful file-level directives that allow you to declare packages, SDKs, and build properties — all without leaving your single .cs file.
The #: prefix is recognized at the C# 14 language level as an ignored directive — meaning the compiler sees it but skips it, letting the CLI layer handle it.
📦 Adding NuGet Packages
#:package Newtonsoft.Json@13.0.3
#:package CsvHelper@33.1.0
using Newtonsoft.Json;
// ... your code
The package is restored automatically when you run the script — no dotnet add package required. You can also use wildcards like @* to grab the latest version.
🌐 Switching the SDK (Hello, ASP.NET Minimal APIs!)
#:sdk Microsoft.NET.Sdk.Web
var app = WebApplication.CreateBuilder(args).Build();
app.MapGet("/", () => "Hello from a single .cs file!");
app.Run();
Just run dotnet run app.cs, then open http://localhost:5000 in your browser — et voilà! A complete ASP.NET Minimal API from just one .cs file.
⚙️ Setting Build Properties
#:property Nullable enable
#:property LangVersion preview
A Real-World Example: Sales Report Generator
Here’s where C# scripting starts to feel genuinely competitive with Python:
#:package CsvHelper@33.1.0
using System.Text.Json;
using CsvHelper;
using System.Globalization;
var json = await File.ReadAllTextAsync("sales_data.json");
var sales = JsonSerializer.Deserialize<List<SaleRecord>>(json);
var topProducts = sales
.GroupBy(s => s.Product)
.Select(g => new {
Product = g.Key,
TotalRevenue = g.Sum(s => s.Amount),
UnitsSold = g.Count()
})
.OrderByDescending(p => p.TotalRevenue)
.Take(10);
using var writer = new StreamWriter("top_products.csv");
using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
csv.WriteRecords(topProducts);
Console.WriteLine("Report generated! Check top_products.csv");
record SaleRecord(string Product, decimal Amount, DateTime Date);
Notice how you’re mixing package references, async operations, LINQ, and record types — all in a single file that reads like a cohesive script. This is the kind of thing you’d typically reach for Python for, but now you can stay in C# land.
When Should You Use File-Based Apps?
File-based apps are perfect for: quick prototyping to test an idea in seconds without creating a full project; scripting in C# to replace Bash or PowerShell scripts with type-safe code; one-off utilities like data converters or file processors; and better samples, where library authors can include runnable examples without cluttering repos with project files.
Use file-based apps when:
- You’re learning or teaching C#
- You need a quick automation script
- You’re demoing a concept
- You want to share a runnable example without a whole repo
Stick with full projects when:
- You’re building production software
- You need multiple files (coming in .NET 11)
- You need full IDE debugging support
The Escape Hatch: Graduating to a Full Project
A file-based app is not something you will outgrow — it’s something you will grow out of, gracefully. The .NET 10 SDK includes a tool that converts it into a full project with a .csproj, keeping your package references and settings.
dotnet project convert app.cs
This command makes a copy of the .cs file and creates a .csproj file with equivalent SDK items, properties, and package references based on the original file's #: directives. Both files are placed in a directory named for the application next to the original .cs file, which is left untouched.
vs. Scripts, Console Apps & Old Workarounds

Community projects like CS-Script, dotnet-script, Cake, and others have long filled this role — but with built-in support, developers can get started immediately: no additional installation, configuration, or discovery steps required.
Platform Notes
The core single-file execution works on Windows, macOS, and Linux. The only platform-specific feature is shebang scripts (#!/usr/bin/env dotnet run), which are Unix-only.
On Unix, you can make your .cs file directly executable:
#!/usr/bin/env dotnet run
Console.WriteLine("I run like a shell script!");
What’s Coming Next
In upcoming .NET previews, Microsoft is aiming to improve the experience in VS Code, with enhanced IntelliSense for the new file-based directives, improved performance, and support for debugging. At the command line, they’re exploring support for file-based apps with multiple files. Multi-file support is currently slated for .NET 11.
Conclusion
By allowing a single .cs file to be compiled and executed directly, this feature lowers the entry barrier for new developers, simplifies experimentation, and makes C# feel more approachable for scripting, tooling, and learning scenarios.
C# has always been powerful. Now it’s fast to start. Whether you’re a seasoned backend engineer wanting to dash off a quick data script, or a newcomer who’s been intimidated by .csproj files — .NET 10's file-based apps hand you the same language you'd use to build enterprise software, with zero ceremony.
The era of “I’ll just use Python for this one” is over.
메타데이터
- post_id
- c7486fcf4bb2
- slug
- dotnet-run-hello-cs-c-finally-got-its-python-moment-in-net-10-c7486fcf4bb2
- url
- https://medium.com/@Rajdip27/dotnet-run-hello-cs-c-finally-got-its-python-moment-in-net-10-c7486fcf4bb2
- canonical_url
- https://medium.com/@Rajdip27/dotnet-run-hello-cs-c-finally-got-its-python-moment-in-net-10-c7486fcf4bb2
- author_url
- https://medium.com/@Rajdip27
- status
- ok
- fetched_at
- 2026-06-26 03:39:16