csharp-file-based-apps
Skill2 starsChanged 8 months agoMITView on GitHub
Use this skill whenever the user is working with C# file-based apps on the latest .NET, including single-file C# programs run with `dotnet run file.cs`, `dotnet file.cs`, or stdin, `#:` directives such as `#:package`, `#:property`, `#:project`, `#:sdk`, and `#:include`, converting utility scripts into file-based apps, packaging them as .NET tools, publishing with Native AOT, or troubleshooting cache, launch profile, and folder layout issues. Trigger even when the user only says "single-file C# app", "projectless C# script", or asks how to run a .cs file directly without creating a .csproj.
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- azure-paas-supportSkill
- azure-resource-abbreviationsSkill
- backlog-apiSkill
- dependabot-auto-mergeSkill
- devblog-updatesSkill
- github-changelogSkill
- github-entra-federated-credentialsSkill
- git-worktreeSkill
- hatena-blog-publisherSkill
- marp-cssSkill
- marp-deckSkill
- summarized-postSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Use references/file-based-apps.md for the core reference.
- Very specific: line 25
Start from the minimal samples in the Examples section when you need working code.
- Very specific: line 32
Check references/file-based-apps.md for supported directives, CLI behavior, and constraints.
- Distinctive: line 33
When proposing code or commands, make these points explicit:
- Distinctive: line 38
Prefer the smallest single-file example that actually works, and only introduce extra files or conversion steps when there is a clear …
- Distinctive: line 39
Only state behavior as fact when it is supported by Microsoft Learn.
- Distinctive: line 71
Do not invent unsupported directives.
- Very specific: line 89
If a .csproj exists in the current directory, dotnet run app.cs might, for backward compatibility, run that project and pass app.cs as an …
- Very specific: line 110
Use #:property PublishAot=false or #:property PackAsTool=false when you need to override those defaults.
- Very specific: line 119
Consider moving app.cs outside the .csproj directory tree.
- Very specific: line 125
If needed, run dotnet build app.cs and then dotnet run app.cs --no-build
- Very specific: line 139
Avoid placing a utility-style app.cs inside a .csproj cone.
- Distinctive: line 140
Use a separate directory for standalone scripts and utilities.
- Distinctive: line 146
When responding, prefer this order when it fits the request:
- Very specific: line 152
If the request involves conversion or architectural choice, explain why a file-based app is a good fit and when a normal .csproj would be a …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
C# File-based Apps Skill
This skill covers C# file-based apps on the latest .NET. Use it for single-file .cs execution with dotnet run app.cs or dotnet app.cs, #: directives, publish / pack / convert workflows, launch profiles, user secrets, build caching, and folder layout guidance.
Skill directory
~/.copilot/skills/csharp-file-based-apps/
Quick Reference
- Use
references/file-based-apps.mdfor the core reference. - Start from the minimal samples in the
Examplessection when you need working code.
Workflow
- First determine whether the user needs a new file-based app, an improvement to an existing utility, a conversion from or to a traditional
.csproj, or troubleshooting. - Check
references/file-based-apps.mdfor supported directives, CLI behavior, and constraints. If you need examples, prefer the samples in this SKILL.md and the bundled reference. - When proposing code or commands, make these points explicit:
- SDK requirements and prerequisites (.NET 10 SDK or later;
#:includerequires SDK 10.0.300+ / .NET 11 Preview 3+) - Which
#:directives are appropriate - Whether
dotnet run,build,publish,pack,restore, orproject convertis the right command - Whether implicit files such as
Directory.Build.propsorglobal.jsonmight affect the result
- SDK requirements and prerequisites (.NET 10 SDK or later;
- Prefer the smallest single-file example that actually works, and only introduce extra files or conversion steps when there is a clear reason.
- Only state behavior as fact when it is supported by Microsoft Learn. Call out preview-only features and OS-specific differences.
What to help with
- Running, building, and distributing a single
.csfile - Choosing the right
#:directives - NuGet package references, project references, and MSBuild properties
- Native AOT defaults and how to disable them
- Packing as a .NET tool
- Converting to a traditional project with
dotnet project convert - Launch profiles via
app.run.json dotnet user-secrets ... --file app.cs- Troubleshooting build cache and folder layout issues
Supported directives
File-based apps place #: directives at the top of the C# file.
| Directive | Purpose | Example |
#:package | Add a NuGet package reference | #:package Spectre.Console@* |
#:property | Set an MSBuild property | #:property PublishAot=false |
#:project | Reference another project | #:project ../Shared/Shared.csproj |
#:sdk | Select the SDK | #:sdk Microsoft.NET.Sdk.Web |
#:include | Include extra files | #:include shared/**/*.cs |
Guidance
- Do not invent unsupported directives. Use only the five directives listed above.
- For
#:package, prefer explicit versions unless the repo uses central package management. Use@*when "latest available" is the goal. - Included
.csfiles in#:includecannot contain top-level statements. Use them for types, methods, namespaces, and related declarations. #:propertycan use MSBuild property functions and environment variables, but keep the setup understandable and explain why it is needed.- For ASP.NET Core or configuration-driven examples, consider
#:sdk Microsoft.NET.Sdk.Web.
CLI patterns
Run
dotnet run app.cs
dotnet app.cs
dotnet run app.cs -- arg1 arg2- If a
.csprojexists in the current directory,dotnet run app.csmight, for backward compatibility, run that project and passapp.csas an argument. Use--filewhen you need unambiguous file-based behavior.
Build / Clean / Restore
dotnet build app.cs
dotnet clean app.cs
dotnet restore app.cs
dotnet clean file-based-appsPublish / Pack / Convert
dotnet publish app.cs
dotnet pack app.cs
dotnet project convert app.cspublishenables Native AOT by default.packdefaults toPackAsTool=true.- Use
#:property PublishAot=falseor#:property PackAsTool=falsewhen you need to override those defaults.
Troubleshooting checklist
1. A project runs when you meant to run the file-based app
- Use
dotnet run --file app.cs. - Consider moving
app.csoutside the.csprojdirectory tree.
2. Build caching looks wrong
dotnet clean app.csdotnet clean file-based-apps- If needed, run
dotnet build app.csand thendotnet run app.cs --no-build
3. Implicit build files are affecting behavior
Directory.Build.propsDirectory.Build.targetsDirectory.Packages.propsnuget.configglobal.json
Any of these in parent directories can affect the file-based app and often explain surprising behavior.
4. The folder layout is working against you
- Avoid placing a utility-style
app.csinside a.csprojcone. - Use a separate directory for standalone scripts and utilities.
Output expectations
When responding, prefer this order when it fits the request:
- Shortest correct answer: what to run, add, or change
- Sample code: the smallest single
.csfile that works - Notes: SDK requirements, preview limitations, cache behavior, or folder layout caveats
If the request involves conversion or architectural choice, explain why a file-based app is a good fit and when a normal .csproj would be a better option.
Examples
Minimal console example
#:package Spectre.Console@*
using Spectre.Console;
AnsiConsole.MarkupLine("[green]Hello from a file-based app[/]");Run:
dotnet run hello.csDisable Native AOT for a quick utility
#:property PublishAot=false
Console.WriteLine("Utility script");Web app style
#:sdk Microsoft.NET.Sdk.Web
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => Results.Ok(new { message = "hello" }));
app.Run();References
- Detailed reference: references/file-based-apps.md
- Source domain: https://learn.microsoft.com/en-us/dotnet/core/sdk/file-based-apps
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
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.

