C# Feature - File-based app directives
File-based app directives
Section titled βFile-based app directivesβC# 14 expands file-based apps with new directives that configure single-file applications directly inside the .cs file.
Introduced In
Section titled βIntroduced InβThis feature was introduced in C# 14. The official Microsoft Learn page for C# 14 is dated November 18, 2025 and states that C# 14 ships with .NET 10 and Visual Studio 2026.
What Was Added
Section titled βWhat Was Addedβ#!for the shebang line used by Unix shells#:for build-system directives used in file-based apps
Common #: directives include:
#:package#:project#:property#:sdk
Example
Section titled βExampleβ#!/usr/bin/env dotnet#:package Spectre.Console@*#:property PublishAot=false
Console.WriteLine("Hello from a file-based app");When To Use It
Section titled βWhen To Use Itβ- Use it for small utilities, demos, scripts, prototypes, or single-file tools.
- Use it when a full project file would be unnecessary ceremony.
Common Pitfalls
Section titled βCommon Pitfallsβ- File-based apps are intentionally lightweight, but they are not always the right structure for growing applications.
- Keep the directives minimal and convert to a project when the app becomes more complex.