agentleFS
mag1artmag1art/skills/dotnet-file-based-apps/SKILL.md

dotnet-file-based-apps

Skill1 starsChanged 3 months agoApache-2.0View on GitHub

Use for .NET 10 file-based C# applications that run from a single .cs file without a traditional .csproj project file.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 17 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use for .NET 10 SDK file-based apps: scripts, command-line utilities, prototypes, small tools, one-off automation, and applications that …

    line 24
  2. Distinctive:

    Do not use this model for a large multi-project solution, a service with complex build configuration, a shared library, or an application …

    line 28
  3. Distinctive:

    Run it with an explicit file option:

    line 47
  4. Distinctive:

    Place directives at the top of the C# file.

    line 63
  5. Distinctive:

    Prefer explicit package versions.

    line 71
  6. Distinctive:

    Do not place application statements before directives.

    line 86
  7. Distinctive:

    Test trimming, reflection, serializers, dynamic loading, and platform-specific dependencies before relying on Native AOT.

    line 104
  8. Distinctive:

    Use the SDK conversion command when the app needs a normal project structure:

    line 108
  9. Distinctive:

    Use user secrets instead of source-controlled credentials:

    line 120
  10. Distinctive:

    Never put real secrets in the source file or command history.

    line 127
  11. Distinctive:

    Keep each independent file-based app in an isolated directory when it needs different build settings.

    line 146
  12. Distinctive:

    Do not place a file-based app inside the directory cone of an unrelated .csproj.

    line 147
  13. Distinctive:

    Keep included files and resources close to the entry file and document their role.

    line 148
  14. Distinctive:

    Use a traditional project when tests, multiple executables, analyzers, packaging, or deployment settings become substantial.

    line 149
  15. Distinctive:

    Verify SDK version, directives, package versions, implicit build files, restore, build, run arguments, publish output, Native AOT …

    line 153
  16. Distinctive:

    Run it explicitly when the directory also contains a project:

    line 167
  17. Distinctive:

    Keep package versions intentional and convert the file to a normal project when it needs tests, multiple source files, complex build …

    line 174

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

.NET File-Based Apps

When to Use

Use for .NET 10 SDK file-based apps: scripts, command-line utilities, prototypes, small tools, one-off automation, and applications that benefit from a single self-contained C# source file.

When Not to Use

Do not use this model for a large multi-project solution, a service with complex build configuration, a shared library, or an application that needs extensive IDE/project tooling. Convert it to a traditional project when the source, dependencies, tests, or deployment process outgrow one file.

Requirements

File-based apps require the .NET 10 SDK or later. Check the active SDK and repository-level global.json before using them:

dotnet --info
dotnet --list-sdks

The SDK creates a virtual project from the directives in the source file. A traditional .csproj is not required.

Minimal File

Console.WriteLine("Hello from a file-based app");

Run it with an explicit file option:

dotnet run --file app.cs

The shorthand forms are dotnet run app.cs and dotnet app.cs. If a project file exists in the current directory, prefer --file because dotnet run app.cs may run the existing project and pass app.cs as an application argument.

Pass arguments after the separator:

dotnet run --file app.cs -- input.json --verbose

Configuration Directives

Place directives at the top of the C# file. Supported directives are:

  • #:package Package.Name@1.2.3 — add an explicit NuGet package reference;
  • #:project ../Shared/Shared.csproj — reference another project;
  • #:property TargetFramework=net10.0 — set an MSBuild property;
  • #:sdk Microsoft.NET.Sdk.Web — select an SDK such as the web SDK;
  • #:include helpers.cs — include additional source/resource files where supported by the SDK.

Prefer explicit package versions. A version can be omitted only when central package management is configured; otherwise use a version or the documented @* form.

Example:

#:
#:sdk Microsoft.NET.Sdk.Web
#:package Spectre.Console@0.49.1
#:property PublishAot=false

using Spectre.Console;

AnsiConsole.MarkupLine("[green]Ready[/]");

Do not place application statements before directives. Included .cs files can add declarations, but cannot add another set of top-level statements.

Build, Publish, and Pack

dotnet restore app.cs
dotnet build app.cs --output ./build
dotnet publish app.cs --output ./publish
dotnet pack app.cs

Native AOT publishing and PackAsTool are enabled by default. Disable them explicitly when the application or dependency graph is not compatible:

#:property PublishAot=false
#:property PackAsTool=false

Test trimming, reflection, serializers, dynamic loading, and platform-specific dependencies before relying on Native AOT.

Convert to a Traditional Project

Use the SDK conversion command when the app needs a normal project structure:

dotnet project convert app.cs

The command creates a copy and a .csproj with equivalent SDK items, properties, and package references. It leaves the original .cs file untouched. Review the generated project before committing it.

Configuration and Secrets

File-based apps respect global.json, Directory.Build.props, Directory.Build.targets, Directory.Packages.props, and nuget.config in their directory or parent directories. Isolate file-based apps from a nearby .csproj project when implicit settings could interfere.

Use user secrets instead of source-controlled credentials:

dotnet user-secrets set "ApiKey" "value" --file app.cs
dotnet user-secrets list --file app.cs

Never put real secrets in the source file or command history.

Launch Profiles

For app.cs, a flat app.run.json next to the source can define development profiles. A traditional Properties/launchSettings.json takes priority when both exist. Use launch profiles for local behavior, not production secrets.

Caching and Concurrency

The SDK caches file-based app build outputs under a temporary runfile directory. Changes to implicit build files or moving files can be confusing during development. If concurrent invocations contend for the same output, build once and run without rebuilding:

dotnet build app.cs
dotnet run app.cs --no-build

Clear stale file-based caches with dotnet clean file-based-apps or clean the individual file before rebuilding.

Layout Rules

  • Keep each independent file-based app in an isolated directory when it needs different build settings.
  • Do not place a file-based app inside the directory cone of an unrelated .csproj.
  • Keep included files and resources close to the entry file and document their role.
  • Use a traditional project when tests, multiple executables, analyzers, packaging, or deployment settings become substantial.

Quality Gate

Verify SDK version, directives, package versions, implicit build files, restore, build, run arguments, publish output, Native AOT compatibility, secrets handling, cache behavior, and the conversion path to .csproj.

Official reference: https://learn.microsoft.com/en-us/dotnet/core/sdk/file-based-apps

Example: Single-File Utility

#:package Spectre.Console@0.49.1

using Spectre.Console;

AnsiConsole.MarkupLine("[green]File-based app started[/]");

Run it explicitly when the directory also contains a project:

dotnet run --file tools/report.cs -- --input data.json
dotnet project convert tools/report.cs

Keep package versions intentional and convert the file to a normal project when it needs tests, multiple source files, complex build properties, or team-scale maintenance.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.