dotnet run app.cs – Run C# Without a Project in .NET 10

If you’ve ever wanted to quickly try out a C# snippet or automate something simple without setting up a full .NET project — you’re not alone.

With the release of .NET 10 Preview 4, that’s finally changing

You can now run a C# file directly using:

C#
dotnet run app.cs

Yes, no .csproj file needed. No scaffolding. No boilerplate. Just a single .cs file — and you’re off

Why This Matters

Up until now, running C# from the command line required creating a project using:

C#
dotnet new console -n MyApp

That’s fine for full applications, but if you’re:

  • Learning C#
  • Writing quick utilities or automation
  • Experimenting with a new API or idea

..spinning up an entire project for that? It’s unnecessary overhead.

With file-based apps in .NET 10, you can now run a single .cs file — just like you would in Python, JavaScript, or Go.

Simple. Fast. To the point.

Let’s See It in Action

Create a new file:

C#
// hello.cs
Console.WriteLine("Hello, world!");

Then run it using:

C#
dotnet run hello.cs

That’s all. No project. Just your code.

Add Power with File-Level Directives

What if you want to use a NuGet package or change the SDK? .NET 10 introduces file-level directives that make this possible — right inside your .cs file.

1. Reference NuGet Packages

C#
#:package Humanizer@2.14.1

using Humanizer;

var releaseDate = DateTimeOffset.Parse("2025-06-17");
Console.WriteLine($"Released {releaseDate.Humanize()} ago");

No need to add a .csproj — just write code and go.

2. Change the SDK

By default, file-based apps use Microsoft.NET.Sdk, but you can switch it using:

C#
#:sdk Microsoft.NET.Sdk.Web

This enables web-specific features like minimal APIs, even in a single file.

3. Set MSBuild Properties

Want to use C# preview features?

C#
#:property LangVersion preview

Set language version, output types, and more — without leaving the file.

Evolve into a Full Project

Started with a single file, but now your script’s growing?

Convert it into a full project with one command:

C#
dotnet project convert app.cs

This will:

  • Create a .csproj file
  • Move your code into Program.cs
  • Add references and properties automatically

It’s a seamless upgrade path.

Example

Here’s a minimal API — in a single .cs file:

C#
#:sdk Microsoft.NET.Sdk.Web
#:package Microsoft.AspNetCore.OpenApi@10.*-*

var builder = WebApplication.CreateBuilder();

builder.Services.AddOpenApi();

var app = builder.Build();

app.MapGet("/hello-world", () => "Hello, world!");
app.Run();

The generated .csproj would be:

JSON
<Project Sdk="Microsoft.NET.Sdk.Web">

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

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.*-*" />
  </ItemGroup>

</Project>

You can run this with:

C#
dotnet run app.cs

And convert it into a project later if needed.

Getting Started

  1. Install .NET 10 Preview 4: Download here
  2. Use VS Code (Recommended) – Make sure to enable pre-release of the C# Dev Kit for full file-based app support.
  3. Write your .cs file
  4. Run it
C#
dotnet run yourfile.cs

Summary

The new dotnet run app.cs feature in .NET 10 brings a lightweight, script-like experience to C# development.

You can now:

  • Run .cs files directly — no project file needed
  • Reference NuGet packages using #:package
  • Set SDKs and build properties inline with #:sdk and #:property
  • Use shebang (#!) for shell scripting on Unix-based systems
  • Seamlessly convert your script into a full .NET project when needed

This approach is ideal for quick prototypes, automation scripts, learning exercises, or even building small command-line tools — all without the overhead of scaffolding a full solution.

Takeaway

C# has always been powerful — but now, it’s also simple to start with.

dotnet run app.cs lowers the entry barrier, speeds up development, and gives you flexibility without compromising structure.

It’s a welcome improvement that feels long overdue.

If you’re using .NET 10 Preview 4 or above, try this out in your next experiment or side project — and see just how fast you can go from idea to execution.

Walkthrough Video: dotnet run app.cs in .NET 10