Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

dotnet-api-versioningdotnet API versioning 搜索

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

303

周安装

13

GitHub Stars

15

下载量

106
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dotnet-api-versioning(dotnet API versioning 搜索)
来源仓库:https://github.com/wshaddix/dotnet-skills
仓库路径:skills/dotnet-api-versioning
安装命令:
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-api-versioning
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-api-versioning

简介

dotnet-api-versioning 提供 ASP.NET Core 的 API 版本化策略,推荐 URL segment 版本控制。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中需要 URL、header 或 query string 版本化时使用。
  • 通过 GitHub 安装,使用 Asp.Versioning 库,支持 sunset 策略和 Minimal API/MVC 配置。
  • 使用前需确认路由组和 endpoint filter 配置,并了解与 OpenAPI 生成的集成方式。
  • 适用于需要长期维护和渐进演化的 API 项目,提供清晰的版本生命周期管理。

SKILL.md

dotnet-api-versioning

API versioning strategies for ASP.NET Core using the Asp.Versioning library family. URL segment versioning (/api/v1/) is the preferred approach for simplicity and discoverability. This skill covers URL, header, and query string versioning with configuration for both Minimal APIs and MVC controllers, sunset policy enforcement, and migration from legacy packages.

Out of scope: Minimal API endpoint patterns (route groups, filters, TypedResults) -- see [skill:dotnet-minimal-apis]. OpenAPI document generation per API version -- see [skill:dotnet-openapi]. Authentication and authorization per version -- see [skill:dotnet-api-security].

Cross-references: [skill:dotnet-minimal-apis] for Minimal API endpoint patterns, [skill:dotnet-openapi] for versioned OpenAPI documents.


Package Landscape

PackageTargetStatus
Asp.Versioning.HttpMinimal APIsCurrent
Asp.Versioning.Mvc.ApiExplorerMVC controllers + API ExplorerCurrent
Asp.Versioning.MvcMVC controllers (no API Explorer)Current
Microsoft.AspNetCore.Mvc.VersioningMVC controllersLegacy -- migrate to Asp.Versioning.Mvc
Microsoft.AspNetCore.Mvc.Versioning.ApiExplorerMVC + API ExplorerLegacy -- migrate to Asp.Versioning.Mvc.ApiExplorer

Install for Minimal APIs:

<PackageReference Include="Asp.Versioning.Http" Version="8.*" />

Install for MVC controllers:

<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.*" />

URL Segment Versioning (Preferred)

URL segment versioning embeds the version in the path (/api/v1/products). It is the simplest strategy, works with all HTTP clients, is cacheable, and clearly visible in logs and documentation.

Minimal APIs

builder.Services.AddApiVersioning(options =>
{
    options.DefaultApiVersion = new ApiVersion(1, 0);
    options.AssumeDefaultVersionWhenUnspecified = true;
    options.ReportApiVersions = true; // Adds api-supported-versions header
    options.ApiVersionReader = new UrlSegmentApiVersionReader();
});

var app = builder.Build();

var versionSet = app.NewApiVersionSet()
    .HasApiVersion(new ApiVersion(1, 0))
    .HasApiVersion(new ApiVersion(2, 0))
    .ReportApiVersions()
    .Build();

var v1 = app.MapGroup("/api/v{version:apiVersion}/products")
    .WithApiVersionSet(versionSet)
    .MapToApiVersion(new ApiVersion(1, 0));

var v2 = app.MapGroup("/api/v{version:apiVersion}/products")
    .WithApiVersionSet(versionSet)
    .MapToApiVersion(new ApiVersion(2, 0));

// V1: returns basic product info
v1.MapGet("/", async (AppDbContext db) =>
    TypedResults.Ok(await db.Products
        .Select(p => new ProductV1Dto(p.Id, p.Name, p.Price))
        .ToListAsync()));

// V2: returns extended product info with category
v2.MapGet("/", async (AppDbContext db) =>
    TypedResults.Ok(await db.Products
        .Select(p => new ProductV2Dto(p.Id, p.Name, p.Price, p.Category, p.CreatedAt))
        .ToListAsync()));

MVC Controllers

builder.Services.AddApiVersioning(options =>
{
    options.DefaultApiVersion = new ApiVersion(1, 0);
    options.AssumeDefaultVersionWhenUnspecified = true;
    options.ReportApiVersions = true;
    options.ApiVersionReader = new UrlSegmentApiVersionReader();
})
.AddMvc()
.AddApiExplorer(options =>
{
    options.GroupNameFormat = "'v'VVV"; // e.g., v1, v2
    options.SubstituteApiVersionInUrl = true;
});

// V1 controller
[ApiController]
[Route("api/v{version:apiVersion}/products")]
[ApiVersion("1.0")]
public sealed class ProductsController(AppDbContext db) : ControllerBase
{
    [HttpGet]
    public async Task<IActionResult> GetAll() =>
        Ok(await db.Products
            .Select(p => new ProductV1Dto(p.Id, p.Name, p.Price))
            .ToListAsync());
}

// V2 controller -- use explicit route, not [controller] token
[ApiController]
[Route("api/v{version:apiVersion}/products")]
[ApiVersion("2.0")]
public sealed class ProductsV2Controller(AppDbContext db) : ControllerBase
{
    [HttpGet]
    public async Task<IActionResult> GetAll() =>
        Ok(await db.Products
            .Select(p => new ProductV2Dto(p.Id, p.Name, p.Price, p.Category, p.CreatedAt))
            .ToListAsync());
}

Header Versioning

Header versioning reads the API version from a custom request header. Keeps URLs clean but is less discoverable and harder to test from a browser.

builder.Services.AddApiVersioning(options =>
{
    options.DefaultApiVersion = new ApiVersion(1, 0);
    options.AssumeDefaultVersionWhenUnspecified = true;
    options.ReportApiVersions = true;
    options.ApiVersionReader = new HeaderApiVersionReader("X-Api-Version");
});

Client request:

GET /api/products HTTP/1.1
Host: api.example.com
X-Api-Version: 2.0

Query String Versioning

Query string versioning uses a query parameter (default: api-version). Simple to use but pollutes URLs and may conflict with caching strategies.

builder.Services.AddApiVersioning(options =>
{
    options.DefaultApiVersion = new ApiVersion(1, 0);
    options.AssumeDefaultVersionWhenUnspecified = true;
    options.ReportApiVersions = true;
    options.ApiVersionReader = new QueryStringApiVersionReader("api-version");
});

Client request:

GET /api/products?api-version=2.0 HTTP/1.1
Host: api.example.com

Combining Version Readers

Multiple readers can be combined. The first reader that resolves a version wins. This is useful during migration from one strategy to another:

options.ApiVersionReader = ApiVersionReader.Combine(
    new UrlSegmentApiVersionReader(),
    new HeaderApiVersionReader("X-Api-Version"),
    new QueryStringApiVersionReader("api-version"));

Sunset Policies

Sunset policies communicate to consumers that an API version is deprecated and will be removed. The Sunset HTTP response header follows RFC 8594.

builder.Services.AddApiVersioning(options =>
{
    options.DefaultApiVersion = new ApiVersion(2, 0);
    options.ReportApiVersions = true;
    options.Policies.Sunset(1.0)
        .Effective(new DateTimeOffset(2026, 6, 1, 0, 0, 0, TimeSpan.Zero))
        .Link("https://docs.example.com/api/migration-v1-to-v2")
            .Title("V1 to V2 Migration Guide")
            .Type("text/html");
});

Response headers for a v1 request:

api-supported-versions: 1.0, 2.0
api-deprecated-versions: 1.0
Sunset: Sun, 01 Jun 2026 00:00:00 GMT
Link: <https://docs.example.com/api/migration-v1-to-v2>; rel="sunset"; title="V1 to V2 Migration Guide"; type="text/html"

Deprecating a Version

Mark a version as deprecated using the version set (Minimal APIs) or attribute (MVC):

// Minimal APIs
var versionSet = app.NewApiVersionSet()
    .HasApiVersion(new ApiVersion(1, 0))
    .HasDeprecatedApiVersion(new ApiVersion(1, 0))
    .HasApiVersion(new ApiVersion(2, 0))
    .ReportApiVersions()
    .Build();

// MVC controllers
[ApiVersion("1.0", Deprecated = true)]
[ApiVersion("2.0")]
public sealed class ProductsController : ControllerBase { }

Migration from Legacy Packages

Projects using Microsoft.AspNetCore.Mvc.Versioning should migrate to Asp.Versioning.Mvc (or Asp.Versioning.Http for Minimal APIs). The API surface is largely compatible with namespace changes:

Legacy namespaceCurrent namespace
Microsoft.AspNetCore.Mvc.VersioningAsp.Versioning
Microsoft.AspNetCore.Mvc.ApiExplorerAsp.Versioning.ApiExplorer

Key migration steps:

  1. Replace NuGet package references
  2. Update using directives from Microsoft.AspNetCore.Mvc.Versioning to Asp.Versioning
  3. Update service registration from services.AddApiVersioning() (legacy extension) to the current extension from Asp.Versioning
  4. Review any custom IApiVersionReader implementations for breaking changes

See the migration guide for detailed steps.


Version Strategy Decision Guide

StrategyProsConsBest for
URL segment (/api/v1/)Simple, visible, cacheable, works everywhereURL changes per versionPublic APIs, most projects (preferred)
Header (X-Api-Version: 1.0)Clean URLs, no path changesLess discoverable, harder to testInternal APIs with controlled clients
Query string (?api-version=1.0)Easy to add, no path changesPollutes URL, cache key issuesQuick prototyping, legacy compatibility

Recommendation: Start with URL segment versioning for all new projects. Add header or query string readers only when migrating from an existing strategy or when specific client constraints require it.


Agent Gotchas

  1. Do not use the legacy Microsoft.AspNetCore.Mvc.Versioning package for new projects -- use Asp.Versioning.Http (Minimal APIs) or Asp.Versioning.Mvc (MVC controllers).
  2. Do not hardcode version numbers in package references -- use version ranges (e.g., 8.*) so the package version matches the latest compatible release.
  3. Do not forget ReportApiVersions = true -- without it, clients cannot discover available versions from response headers.
  4. Do not mix MapToApiVersion and route group prefixes inconsistently -- each route group should target exactly one API version.
  5. Do not deprecate a version without a sunset policy -- always provide a sunset date and migration link so consumers can plan.
  6. Do not use AssumeDefaultVersionWhenUnspecified = true for public APIs -- it hides versioning requirements from consumers. Require explicit version selection instead.

Prerequisites

  • .NET 8.0+ (LTS baseline)
  • Asp.Versioning.Http for Minimal APIs
  • Asp.Versioning.Mvc.ApiExplorer for MVC controllers with API Explorer integration

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.94%
按下载量换算37

Claude

28.28%
按下载量换算30

Cursor

19.03%
按下载量换算20

Gemini CLI

10.37%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills