Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

dotnet-file-based-apps

БесплатноБез исполняемых скриптовНе проверен

Running C# without a project file (.NET 10 SDK). Directives, CLI commands, migration.

wshaddixот wshaddix★ 94 звезды на GitHub

Об этом скилле

dotnet-file-based-apps

.NET 10 SDK file-based apps let you build, run, and publish C# applications from a single .cs file without creating a .csproj project file. The SDK auto-generates project configuration from #: directives embedded in the source file. This feature targets scripts, utilities, and small applications where traditional project scaffolding is unnecessary.

This is NOT file I/O. For FileStream, RandomAccess, FileSystemWatcher, and path handling, see [skill:dotnet-file-io].

Prerequisites: Requires .NET 10 SDK or later. Run [skill:dotnet-version-detection] to confirm SDK version.

Cross-references: [skill:dotnet-version-detection] for SDK version gating, [skill:dotnet-project-analysis] for project-based analysis (file-based apps have no .csproj), [skill:dotnet-scaffold-project] for csproj-based project scaffolding.


Directives Overview

File-based apps use #: directives to configure the build. Directives are SDK-level instructions, not C# syntax. They must appear at the top of the .cs file, before any C# code.

Four directive types are supported:

Directive Purpose Example
#:package Add a NuGet package reference #:package [email protected]
#:sdk Set the SDK (default: Microsoft.NET.Sdk) #:sdk Microsoft.NET.Sdk.Web
#:property Set an MSBuild property #:property PublishAot=false
#:project Reference another project file #:project ../Lib/Lib.csproj

#:package Directive

Adds a NuGet package reference. Specify the package name, optionally followed by @version.

#:package Newtonsoft.Json
#:package [email protected]
#:package Spectre.Console@*

Version behavior:

  • @version -- pins to a specific version
  • @* -- uses the latest stable version (NuGet floating version)
  • No version -- only works when Central Package Management (CPM) is configured with a Directory.Packages.props file; otherwise, specify a version explicitly or use @*

#:sdk Directive

Specifies which SDK to use. Defaults to Microsoft.NET.Sdk if omitted.

#:sdk Microsoft.NET.Sdk.Web
#:sdk [email protected]

Use this directive to access SDK-specific features. For example, Microsoft.NET.Sdk.Web enables ASP.NET Core features and automatically includes *.json configuration files in the build.


#:property Directive

Sets an MSBuild property value. Use this to customize build behavior.

#:property TargetFramework=net10.0
#:property PublishAot=false

Conditional Property Values

Property directives support MSBuild property functions and expressions for conditional configuration.

Environment variables with defaults:

#:property LogLevel=$([MSBuild]::ValueOrDefault('$(LOG_LEVEL)', 'Information'))

Conditional expressions:

#:property EnableLogging=$([System.Convert]::ToBoolean($([MSBuild]::ValueOrDefault('$(ENABLE_LOGGING)', 'true'))))

#:project Directive

References another project file or directory containing a project file. Use this to share code between a file-based app and a traditional project.

#:project ../SharedLibrary/SharedLibrary.csproj

The referenced project is built and linked as a project reference, just like <ProjectReference> in a .csproj.


CLI Commands

The .NET CLI supports file-based apps through familiar commands.

Run

# Preferred: pass file directly
dotnet run app.cs

# Explicit --file option
dotnet run --file app.cs

# Shorthand (no 'run' subcommand)
dotnet app.cs

# Pass arguments after --
dotnet run app.cs -- arg1 arg2

When a .csproj exists in the current directory, dotnet run app.cs (without --file) runs the project and passes app.cs as an argument to preserve backward compatibility. Use dotnet run --file app.cs to force file-based execution.

Pipe from stdin

echo 'Console.WriteLine("hello");' | dotnet run -

The - argument reads C# code from standard input. Useful for quick testing and shell script integration.

Build

dotnet build app.cs

Build output goes to a cached location under the system temp directory by default. Override with --output or #:property OutputPath=./output.

Clean

# Clean build artifacts for a specific file
dotnet clean app.cs

# Clean all file-based app caches in the current directory
dotnet clean file-based-apps

# Clean caches unused for N days (default: 30)
dotnet clean file-based-apps --days 7

Publish

dotnet publish app.cs

File-based apps enable native AOT by default. The output goes to an artifacts directory next to the .cs file. Disable AOT with #:property PublishAot=false.

Pack as .NET Tool

dotnet pack app.cs

File-based apps set PackAsTool=true by default. Disable with #:property PackAsTool=false.

Restore

dotnet restore app.cs

Re

Полный SKILL.md на GitHub

Установить dotnet-file-based-apps в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл dotnet-file-based-apps?

Running C# without a project file (.NET 10 SDK). Directives, CLI commands, migration.

Как установить скилл dotnet-file-based-apps?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл dotnet-file-based-apps запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить dotnet-file-based-apps с