Dotnet Run App
Have you ever had a moment of inspiration, an idea you wanted to test in C#, but didn’t want to spin up a full project just to run a few lines of code? Same here.
Well, with .NET 10 Preview 4, that pain is going away. Say hello to the new dotnet run app.cs
feature.
It’s like C# finally took a page from Python and JavaScript, languages that have long made it easy to run a file with a single command. Now C# joins the party. 🎉
Try It Out: Instant Console Apps
Let’s start simple. We’ll create a new file-based app with a little file called Champions.cs
:
|
|
Just run it with:
|
|
And that’s it. No Program.cs
, no .csproj
files, no boilerplate. Just your code, running instantly.
Go Bigger: Run a Minimal API from a Single File
Here’s where it gets really cool. You can now run a full ASP.NET Minimal API from a single .cs file too. Check this out:
|
|
Save this as MyApi.cs
, and run:
|
|
Boom 💥 — you’ve got a running local API. No scaffolding, no folders, just fast feedback and working code.
Shell Scripts
I’m not great at writing bash scripts. Truth be told, I rely on my trusty friend, GitHub Copilot, to help write bash scripts. With file-based apps in C#, I can write cross-platform C# shell scripts! 💥
|
|
Growing Up
When the time comes to “grow up” to a full C# project, you can do that with the dotnet project convert
command. Nice!
Why This Matters
This change makes C# a much more approachable language for:
- Rapid prototyping
- Teaching and learning
- Sharing quick samples
- Running minimal tools and APIs on the fly
And honestly… with features like this, I may never need to write another shell script again. (Half joking. Probably. 😁)
Ready to Dive In?
Try it out, share your experiments, and let me know what you build! I’m especially curious if you’ve found creative ways to use this in your day-to-day development.
Check out my very simple sample repo at https://github.com/mcollier/dotnet-run-demo (used to help write this post).
You can read more in the official .NET blog post: 👉 Announcing dotnet run app.cs - A simpler way to start with C# and .NET 10