# Csharp Scripts

Run file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code...

- Repository: https://github.com/dotnet/skills (5787 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add dotnet/skills --skill csharp-scripts -g -a claude-code -y`
Codex: `npx skills add dotnet/skills --skill csharp-scripts -g -a codex -y`
Cursor: `npx skills add dotnet/skills --skill csharp-scripts -g -a cursor -y`
Gemini CLI: `npx skills add dotnet/skills --skill csharp-scripts -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add dotnet/skills`

## Description

Run file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file C# apps, small multi-file C# apps composed with `#:include`/`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python/PowerShell-style automation, full projects, or existing app integration.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# File-Based C# Apps

## When to Use

- Testing a C# concept, API, or language feature with a quick file-based app
- Prototyping logic before integrating it into a larger project
- Building a small utility from one entry-point file and a few helper `.cs` files

## When Not to Use

- The user asks for a language-agnostic quick script, throwaway computation, or shell/Python/PowerShell-style automation
- The user needs a full project, solution integration, or project references in an existing app
- The user is working inside an existing .NET solution and wants to add code there
- The app is large enough that project structure, build customization, tests, or publish configuration should live in a `.csproj`

## Inputs

| Input | Required | Description |
|-------|----------|-------------|
| C# code or intent | Yes | The code to run, or a description of what the file-based app should do |

## Workflow

### Step 1: Check the .NET SDK version

Run `dotnet --version` to verify the SDK is installed and note the full version, including the feature band. File-based apps require .NET 10 or later. `#:include`, `#:exclude`, and transitive directive processing require SDK 10.0.300 or later; SDK 10.0.100/10.0.200 builds can run single-file apps but do not support those multi-file directives. If the version is below 10, follow the [fallback for older SDKs](#fallback-for-net-9-and-earlier) instead.

### Step 2: Write the app file

Create an entry-point `.cs` file using top-level statements. Place it outside any existing project directory to avoid conflicts with `.csproj` files.

```csharp
#!/usr/bin/env dotnet
// hello.cs
Console.WriteLine("Hello from a file-based app!");

var numbers = new[] { 1, 2, 3, 4, 5 };
Console.WriteLine($"Sum: {numbers.Sum()}");
```

Guidelines:

The rest: https://github.com/dotnet/skills/blob/HEAD/plugins/dotnet-advanced/skills/csharp-scripts/SKILL.md
