HomeNikola Knezevic

In this article

Banner

File-Based Apps in .NET 10

20 Nov 2025
5 min

Sponsor Newsletter

.NET 10 was released last week, bringing a ton of new features as always.

But this release could be one of the most impactful in recent years.

In this post, we’ll focus on file-based apps, a feature that could be a real game changer for C#.

File-Based Apps

Traditionally, even to print a simple "Hello World" you needed:

  • Solution
  • Project inside the solution
  • A Program.cs file inside that project

This structure is perfect for large applications, but for beginners or anyone who just wants to quickly test an idea it's a complete overkill.

By the time Visual Studio finishes creating a new solution, I could have already tested a small snippet in a different language.

In contrast, Python lets you just create a file and run it instantly, with no setup, boilerplate or delay.

With .NET 10, Microsoft has made C# much more approachable. You can now:

  • Create a single .cs file
  • Write your code directly inside
  • Run it with a single command:
shell
dotnet run yourfile.cs

No solution. No project. No boilerplate.

This is ideal for quick experiments and learning C#.

Getting Started

It’s not quite as simple as just creating a file, there’s some new syntax to learn.

Let’s start with a simple "Hello World" program:

csharp
Console.WriteLine("Hello World");

That works immediately, but what if you want to add a class?

To define a class all you need is to define it after your top-level statements.

csharp
Console.WriteLine("Hello World");

public sealed class Product
{
    public Guid Id { get; set; }

    public DateTime CreatedAt { get; set; }

    public DateTime? ModifiedAt { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    public decimal Price { get; set; }
}

If you want to use a NuGet package, you can declare it at the top of the file:

csharp
#:package Bogus@35.*

This tells the compiler to include the Bogus package, and the * allows any version starting with 35. You can also specify an exact version if you want.

Here’s a more complete example using a package:

csharp
#:package Bogus@35.*


using Bogus;
using System;


var faker = new Faker<Product>()
            .RuleFor(x => x.Id, f => f.Random.Guid())
            .RuleFor(x => x.CreatedAt, f => f.Date.Past())
            .RuleFor(x => x.Name, f => f.Commerce.ProductName())
            .RuleFor(x => x.Description, f => f.Commerce.ProductDescription())
            .RuleFor(x => x.Price, f => f.Random.Decimal());

var products = faker.Generate(10);

foreach(var product in products)
{
    Console.WriteLine($"Product: Id - {product.Id}, Name - {product.Name}");
}

public sealed class Product
{
    public Guid Id { get; set; }

    public DateTime CreatedAt { get; set; }

    public DateTime? ModifiedAt { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    public decimal Price { get; set; }
}

You can also configure file-level properties. For example, to enable nullable references:

csharp
#:property Nullable enable

File-Based Web APIs

Yes, you can even build a Web API as a single file.

The only requirement is to specify the SDK at the top:

csharp
#:sdk Microsoft.Net.Sdk.Web

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.Run();

To add packages, place them below the SDK line:

csharp
#:sdk Microsoft.Net.Sdk.Web

#:package Swashbuckle.AspNetCore@10.0.1

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI();

app.MapGet("/hello", () => Results.Text("Hello World!"));

app.Run();

Publishing and Converting

You can publish a file-based app just like any other project:

shell
dotnet publish app.cs

If your app is growing and you want to switch to a traditional full project structure, it can be converted instantly using:

shell
dotnet project convert app.cs

This creates a .csproj file that includes everything automatically:

csharp
<Project Sdk="Microsoft.Net.Sdk.Web">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
  </ItemGroup>

</Project>

Why it matters?

This feature makes C# far more approachable for newcomers, which is key.

Beginners can now focus on learning the language itself, rather than starting with a whole solution, project structure, boilerplate and other distractions.

I’d love to see future updates enable importing other files or referencing class libraries directly, that would definitely make this feature even more powerful.

Either way, I believe this feature will lower the entry barrier and attract new developers to the .NET ecosystem.

Conclusion

.NET 10’s file-based apps are a major step forward in making C# more accessible, flexible, and beginner-friendly.

This simplification speeds up experimentation and bridges the gap between C# and other languages.

I’m excited to see how this evolves, particularly the ability to import files or reference class libraries directly.

If you want to check out examples I created, you can find the source code here:

Source Code

I hope you enjoyed it, subscribe and get a notification when a new blog is up!

Subscribe

Stay tuned for valuable insights every Thursday morning.