Microsoft introduced one of the most exciting features in .NET — the new dotnet run app command. It’s part of .NET 10, and it completely changes the way we write and run C# code.

No longer do you need to set up a full project just to test something or print “Hello World.” It’s now much more lightweight, flexible, and beginner-friendly.

In this article, we’ll go step by step through what this new feature is, how it works, and how you can go from a simple single-file script to a fully structured .NET project — all within a few minutes.

Getting Started

Let’s begin with a completely empty folder in Visual Studio Code — no project files, no solution, just a blank workspace.

Note: You’ll need .NET 10  and the C# Dev Kit for VS Code installed before starting.

Create a new file named hello.cs. Inside, write the most basic C# code possible:

Console.WriteLine("Hello from .NET 10! This is a cool feature.");

No namespaces, no class, no Main() method — just one file, one line, and that’s it.

Running the File

Here’s the magic part: instead of creating a project, simply open the terminal and type:

dotnet run hello.cs

And it runs instantly!
The output is exactly what we expect:

Hello from .NET 10! This is a cool feature.

.NET compiles and executes the file directly — no extra setup, no project required.
Behind the scenes, it builds your code in memory and runs it like a script.

This approach is perfect for quick experiments or throwaway ideas you want to test fast.

Adding Functionality: Working with Dates

Let’s take it a step further. Suppose we want to print when something was posted — for example, 3 days ago.

Add the following:

var postedDate = DateTime.UtcNow.AddDays(-3);
Console.WriteLine($"Posted date: {postedDate}");

When you run it again, it prints the full date and time as expected.
However, that output isn’t exactly user-friendly — it just dumps a long timestamp string.

So how can we fix that?

Using NuGet Packages Without a Project

Yes, you can now use NuGet packages even without creating a full project.

We’ll use the Humanizer package, which formats dates in a readable way — e.g., “3 days ago” instead of a timestamp.

At the top of your file, add this line:

#r "nuget: Humanizer, 2.14.1"

Then, add:

using Humanizer;

Now update your console output:

var postedDate = DateTime.UtcNow.AddDays(-3);
Console.WriteLine($"Posted {postedDate.Humanize()}");

Run it again:

dotnet run hello.cs

The first run might take a moment as it downloads the package, but after that, it’s instant.
Now your output reads:

Posted 3 days ago

Simple, clean, and human-readable — exactly what we wanted.

Creating a Minimal API in a Single File

Now let’s go even further. What if you want to build a small API inside a single file — without creating a whole project?

Yes, that’s possible too.

Create a new file called api.cs and add the following code:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet(“/testapi”, () => “Hello from .NET 10!”);

app.Run();

Then, try to run it:

dotnet run api.cs

You’ll see an error saying WebApplication does not exist in the current context.
That’s because we haven’t told .NET to use the Web SDK yet.

Adding the Web SDK

To fix this, add the following line at the very top of your file:

#sdk "Microsoft.NET.Sdk.Web"

Now, run it again:

dotnet run api.cs

This time, it works! The API starts and listens on http://localhost:5000.

Use Postman or your browser to visit /testapi, and you’ll see:

Hello from .NET 10!

Your minimal API is fully working — all from a single file.

Converting a Single File into a Project

As your file grows larger — with more endpoints or middleware — you might want to organize it into a proper .NET project.
You don’t have to start from scratch. Just run this command:

dotnet project convert api.cs

.NET automatically:

  • Creates a new project folder

  • Moves api.cs inside

  • Generates a .csproj file

  • Includes all SDKs and package references used

Inside the generated .csproj, you’ll see:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>

Now you can build, restore, and run it like any normal .NET app.

Converting the Hello World Example

You can do the same for your earlier hello.cs file:

dotnet project convert hello.cs

.NET creates a new console project and automatically includes any dependencies you used — such as the Humanizer package.

Here’s what the .csproj looks like:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Humanizer" Version="2.14.1" />
</ItemGroup>
</Project>

Everything is ready to run — and you didn’t have to configure anything manually.

Conclusion

We just went from writing a single C# file with a few lines of code to:

  • Running it directly using dotnet run

  • Using NuGet packages like Humanizer

  • Building a minimal API in a single file

  • Converting those scripts into fully structured projects

—all without setting up anything manually.

.NET 10 is truly redefining how we start coding in C#.
Whether you’re prototyping, scripting, or learning, this new workflow is clean, fast, and beginner-friendly.

If you found this helpful, give the video (or article) a like and stay tuned for more .NET 10 tips and tutorials — including updates on minimal APIs, AI integration, and new .NET Core features.