Executive Summary
In this 100% live-code session, Damian Edwards unveils the evolution of C# File-Based Apps (FBAs) in .NET 11. First introduced in .NET 10, file-based apps allow developers to run, compile, publish, and package standalone .cs files without creating an explicit .csproj project file or a solution directory.
In .NET 11, File-Based Apps evolve from simple single-file scripts into an enterprise-grade execution model. Damian demonstrates that FBAs are full-fat C#, completely distinct from legacy CSX C# scripting: they utilize standard Roslyn compilation, support full C# Dev Kit language server IntelliSense, and leverage intelligent virtual project caching. When files are unchanged, the launch cache executes in ~100 ms, completely bypassing MSBuild and Roslyn.
Key innovations introduced in .NET 11 include:
- Rich Directive Syntax & Metadata:
#:packagewith version floating or Central Package Management (CPM),#:property,#:includewith globbing, and metadata tags likePrivateAssets=all. - App-to-App & Project References: Linking multiple file-based apps via
#:ref other.csand traditional MSBuild class libraries via#:project path/to/lib.csproj. - Single-File ASP.NET Core & Host Integration: Web SDK support (
#:sdk Microsoft.NET.Sdk.Web), convention-based settings (web.settings.json), and run configurations (web.run.json) with VS Code file nesting. - Third-Party MSBuild SDKs: Referencing NuGet-distributed SDKs such as Cake (
cake.cs) directly in single files. - Toolchain-Wide Parity:
dotnet format,dotnet package list --outdated --vulnerable, and community tools likedotnet-outdatedoperating directly on.csfiles. - Unix/Linux Native Shebang & Extensionless Execution: Native execution via
#!/usr/bin/env -S dotnet --,chmod +x, and extensionless CLI tool distribution.
Architectural Deep Dive & Compilation Pipeline
File-Based Apps synthesize a virtual project in memory and cache artifacts within .dotnet/launch-cache. Depending on whether directives, code, or nothing has changed, the CLI selectively bypasses MSBuild evaluation and Roslyn compilation.
flowchart TD
subgraph Input ["Invocation Channels"]
CLI["dotnet run app.cs / dotnet app.cs"]
STDIN["echo 'code' | dotnet run -"]
NIX["./app (Shebang + chmod +x)"]
end
subgraph Parser ["Directives Parser & Hash Evaluation"]
Parse["Scan Top-of-File Directives (#:package, #:property, #:include, #:ref, #:sdk)"]
HashCalc["Compute Cache Key (Source Hash + Directive Fingerprint + CPM Context)"]
end
subgraph CacheBranch ["Cache Decision Engine"]
CacheCheck{"Fingerprint Match in .dotnet/launch-cache?"}
Hit["Skip MSBuild & Roslyn<br/><b>Execution Time: ~100 ms</b>"]
MissCode["Directives Unchanged, Code Changed?<br/><b>Fast Recompile: ~400 ms</b>"]
MissFull["Directives Changed / Uncached?<br/><b>Full MSBuild + Restore: ~1000 ms</b>"]
end
subgraph VirtualProj ["Virtual MSBuild Project Synthesis"]
Synth[".csproj Virtual Memory Model Synthesized"]
Restore["Implicit NuGet Restore (Transitive Dependencies)"]
Emit["Roslyn Emit to Cached Assembly Output"]
end
subgraph Execution ["CoreCLR Execution"]
RunCore["Execute Target Assembly with Arguments"]
end
CLI --> Parse
STDIN --> Parse
NIX --> Parse
Parse --> HashCalc --> CacheCheck
CacheCheck -- "Identical Cache Key" --> Hit --> RunCore
CacheCheck -- "Source Delta Only" --> MissCode --> Emit --> RunCore
CacheCheck -- "Directives / First Run" --> MissFull --> Synth --> Restore --> Emit --> RunCore
Key Technical Innovations
1. Ergonomics & Execution Models
Running standalone C# files requires zero scaffolding:
# Minimal invocation
dotnet hello.cs
# Explicit CLI command
dotnet run hello.cs
# Standard argument forwarding
dotnet run --file hello.cs -- --name "Damian" --verbose
# Unix STDIN piping
"Console.WriteLine(DateTime.UtcNow);" | dotnet run -

Damian Edwards kicks off the live-coding session covering single-file C# in .NET 11.

Executing dotnet run hello.cs directly in the terminal without a .csproj or solution file.

Executing dynamic C# piped directly from standard input using dotnet run -.
2. Not Scripting: Full-Fat C# & Language Server Parity
Unlike legacy C# Interactive (.csx) or script engines:
- Full Roslyn compilation: Full support for C# 12, C# 13, and preview features (
#:property LangVersion=preview). - Standard tooling: Visual Studio Code and Visual Studio C# Dev Kit offer complete code completion, semantic colorization, refactoring, code fixes, and hover documentation.
- Top-Level Statements & Methods: Seamlessly combine top-level statements with local functions, records, and class declarations.
3. Directives System in .NET 11
Directives appear at the top of the .cs file using the #:directive [value] prefix:
#:property LangVersion=preview
#:property TargetFramework=net11.0
#:package Humanizer.Core@2.14.1
#:package Spectre.Console
#:include helpers/formatting.cs
#:include helpers/*.cs
Central Package Management (CPM) Support
If a Directory.Packages.props exists anywhere in the directory hierarchy, #:package PackageName can omit the version (@version). The CLI automatically binds the version declared in the CPM file, ensuring version consistency across both full projects and standalone files.

Referencing external NuGet packages using #:package Humanizer.Core@2.14.1.

Omitting version tags in #:package to inherit versions managed by Directory.Packages.props.
Directive Metadata (PrivateAssets=all)
In .NET 11, directives now accept MSBuild metadata attributes. This is crucial for analyzers, generators, and packages that must not flow transitively:
#:package StyleCop.Analyzers@1.2.0-beta.556 PrivateAssets=all

Adding PrivateAssets=all metadata to package references inside file-based apps.
4. Multi-File Apps & Modular Includes
Single-file apps often outgrow a single file. .NET 11 introduces #:include:
- Explicit files:
#:include helpers/formatting.cspulls helper methods into the compilation. - Transitive dependency resolution: If
formatting.csdeclares#:package Humanizer.Core, that package is automatically pulled into the parent application. - Globbing:
#:include helpers/*.csincludes all matching files. Note: Wildcards currently bypass the launch cache check, causing a full recompilation check.

Including modular helper files and experiencing IntelliSense file path completions.
5. Launch Performance Benchmarks (MeasureLaunch.ps1)
Damian benchmarks execution time across cache states:
| Execution State | Mechanism | Duration |
|---|---|---|
Cold / Uncached (--no-cache) |
Full MSBuild project generation, NuGet restore, Roslyn emit | ~1,000 ms |
| Directive Delta | MSBuild virtual project modified, dependencies re-resolved | ~1,000 ms |
| Source Code Edit Only | Skips MSBuild project synthesis; fast direct Roslyn compilation | ~400 ms |
| Warm Cache Hit (Unchanged) | Bypasses MSBuild & Roslyn entirely; runs cached binary directly | ~100 ms |

Live execution timing: uncached (1.0s), code changed (400ms), cached (~100ms).
6. Single-File ASP.NET Core & Host Integration
Building complete web services in a single file:
#:sdk Microsoft.NET.Sdk.Web
var app = WebApplication.Create(args);
app.MapGet("/", () => Results.Ok(new { status = "online", timestamp = DateTimeOffset.UtcNow }));
app.Run();
Convention-Based Configuration & Run Settings
- Settings:
web.settings.jsonis automatically loaded byWebApplication.Create()orHost.CreateApplicationBuilder()(matchingappsettings.jsonbehavior). - Run Profiles:
web.run.jsonreplacesProperties/launchSettings.json, configuring ports, environment variables, and ASPNETCORE_ENVIRONMENT. - VS Code Nesting: With file nesting enabled,
web.settings.jsonandweb.run.jsonautomatically nest cleanly beneathweb.cs.

Running a full ASP.NET Core web server directly from dotnet web.cs.

VS Code Explorer displaying web.run.json and web.settings.json nested under web.cs.
7. Polyglot Ecosystem & Reference Topologies
.NET 11 bridges file-based apps with the broader .NET ecosystem:
- Third-Party SDKs (
#:sdk Cake.Sdk): Enables single-file C# build scripts with Cake types and targets imported out-of-the-box. - App-to-App References (
#:ref plan.cs): Allows one file-based app to consume types and classes from another.csfile without packaging it to NuGet. - Traditional Project References (
#:project ../projects/brand.csproj): Allows a lightweight file-based app to link directly to enterprise class libraries and domain models.

Using #:sdk Cake.Sdk to write a single-file C# build script.

Combining #:ref plan.cs and #:project ../projects/brand.csproj in a single file.
8. CLI Toolchain Parity & Package Hygiene
In .NET 11, the entire .NET CLI suite has been updated to treat .cs files as first-class project targets:
dotnet format formatme.cs: Formats code against editorconfig conventions.dotnet package list --file packages.cs: Inspects top-level and transitive dependencies.dotnet package list --file packages.cs --outdated: Flags packages with newer versions on NuGet.dotnet package list --file packages.cs --vulnerable: Scans for known security vulnerabilities.dotnet outdated packages.cs: Community tool.NET Outdatedupdated with native file-based app flags (--enable-fb-apps -r).

Running dotnet format formatme.cs to apply whitespace and code style rules.

Listing outdated and vulnerable NuGet packages directly on a .cs file.
9. Linux/Unix Native Shebang & Extensionless Execution
To integrate into Unix workflows and CLI path tooling:
- Add the shebang to line 1 of the file:
#!/usr/bin/env -S dotnet -- using System; Console.WriteLine($"Running as native CLI command. Args: {string.Join(", ", args)}"); - Make the file executable:
chmod +x session.cs ./session.cs arg1 arg2 - Extensionless Support: Create an extensionless file or symlink (
session -> session.cs). The .NET CLI detects the shebang and executes the file seamlessly. Placing it in~/.local/binallows invokingsessionfrom any shell prompt.

Configuring Unix shebang, chmod +x, and extensionless execution in Ubuntu WSL.
Conclusion & Roadmap
File-Based Apps in .NET 11 elevate C# into a premier language for shell scripting, CLI tools, micro-benchmarks, rapid prototyping, and web utilities. By combining ~100ms cached startup, full Roslyn language features, rich directive metadata, and complete CLI command parity, developers get the agility of Python or Node.js with the performance, type safety, and ecosystem power of .NET.
Look for continued refinements in upcoming .NET SDK feature band releases (11.0.200 in early 2027), including further optimizations for glob caching and language server enhancements.