Skip to content

C# Feature - File-based app directives

C# 14 expands file-based apps with new directives that configure single-file applications directly inside the .cs file.

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.

  • #! for the shebang line used by Unix shells
  • #: for build-system directives used in file-based apps

Common #: directives include:

  • #:package
  • #:project
  • #:property
  • #:sdk
#!/usr/bin/env dotnet
#:package Spectre.Console@*
#:property PublishAot=false
Console.WriteLine("Hello from a file-based app");
  • Use it for small utilities, demos, scripts, prototypes, or single-file tools.
  • Use it when a full project file would be unnecessary ceremony.
  • 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.