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.