dotnet-multi-targeting
БесплатноБез исполняемых скриптовНе проверенTargeting multiple TFMs or using newer C# on older TFMs. Polyfill strategy, API compat.
от wshaddix★ 94 звезды на GitHubОб этом скилле
dotnet-multi-targeting
Comprehensive guide for .NET multi-targeting strategies with a polyfill-first approach. This skill consumes the structured output from [skill:dotnet-version-detection] (TFM, C# version, preview flags) and provides actionable guidance on backporting language features, handling runtime gaps, and validating API compatibility across target frameworks.
Out of scope: TFM detection logic (owned by [skill:dotnet-version-detection]), version upgrade lane selection (see [skill:dotnet-version-upgrade]), platform-specific UI frameworks (MAUI, Blazor), cloud deployment configuration.
Cross-references: [skill:dotnet-version-detection] for TFM resolution and version matrix, [skill:dotnet-version-upgrade] for upgrade lane guidance and migration strategies.
Decision Matrix: Polyfill vs Conditional Compilation
Use this matrix to select the correct strategy for each type of gap between your highest and lowest TFMs.
| Gap Type | Strategy | When to Use | Example |
|---|---|---|---|
| Language/syntax feature | Polyfill (PolySharp) | Compiler needs attribute/type stubs to emit newer syntax on older TFMs | required modifier, init properties, SetsRequiredMembers on net8.0 |
| BCL API addition | Polyfill (SimonCropp/Polyfill) if available, else #if |
A newer BCL type or method is missing on older TFMs | System.Threading.Lock on net8.0, Index/Range on netstandard2.0 |
| Runtime behavior difference | Conditional compilation (#if) or adapter pattern |
Behavior differs at runtime regardless of compilation | Runtime-async (net11.0 only), different GC modes, SearchValues<T> runtime optimizations |
| Platform API divergence | Conditional compilation with [SupportedOSPlatform] |
API exists only on specific OS targets | Windows Registry APIs, Android-specific intents, iOS keychain |
Decision flow:
- Can a compile-time polyfill satisfy the gap? Use PolySharp or SimonCropp/Polyfill.
- Is the gap a missing BCL API with no polyfill available? Use
#ifwith TFM-specific code. - Is the gap a runtime behavior difference? Use
#ifor the adapter pattern to isolate divergent code paths. - Is the gap platform-specific? Use
#ifwith[SupportedOSPlatform]attributes.
PolySharp (Compiler-Synthesized Polyfills)
PolySharp is a source generator that synthesizes the attribute and type stubs the C# compiler needs to emit newer language features when targeting older TFMs. It operates entirely at compile time -- no runtime dependencies are added.
What PolySharp Provides
requiredmodifier support (C# 11+)initproperty accessors (C# 9+)SetsRequiredMembersattributeCompilerFeatureRequiredattributeIsExternalInittypeCallerArgumentExpressionattributeStackTraceHiddenattributeUnscopedRefattributeInterpolatedStringHandlerattributesModuleInitializerattribute- Index and Range support types
Setup
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<!-- Use the highest C# version across all TFMs -->
<LangVersion>14</LangVersion>
</PropertyGroup>
<ItemGroup>
<!-- PolySharp is a source generator; it adds no runtime dependency -->
<PackageReference Include="PolySharp" Version="1.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
How It Works
PolySharp detects which polyfill types are missing for the current TFM and generates source for only those types. On net10.0, where required is natively supported, the generator emits nothing -- zero overhead.
// This compiles on net8.0 WITH PolySharp installed,
// because PolySharp generates the required CompilerFeatureRequired
// and IsExternalInit types that the compiler needs.
public class UserProfile
{
public required string DisplayName { get; init; }
public required string Email { get; init; }
public string? Bio { get; set; }
}
PolySharp Limitations
- PolySharp provides compiler stubs only. It does not backport runtime behavior.
- Features that require runtime support (e.g., runtime-async,
SearchValues<T>hardware acceleration) cannot be polyfilled. - If a feature needs both a compiler attribute AND a BCL API (e.g., collection expressions with
Span<T>overloads), you may need both PolySharp and SimonCropp/Polyfill.
SimonCropp/Polyfill (BCL API Polyfills)
SimonCropp/Polyfill provides source-generated implementations of newer BCL APIs for older TFMs. Unlike PolySharp (which provides compiler attribute stubs), Polyfill provides actual method and type implementations.
What Polyfill Provides
Key polyfilled APIs (non-exhaustive):
System.Threading.Lock(C# 13 / net9.0+)String.Contains(char),String.Contains(string, StringComparison)String.ReplaceLineEndings()- `H
Установить dotnet-multi-targeting в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл dotnet-multi-targeting?
Targeting multiple TFMs or using newer C# on older TFMs. Polyfill strategy, API compat.
Как установить скилл dotnet-multi-targeting?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dotnet-multi-targeting запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic