Asgard.TsGen 8.2.0

dotnet add package Asgard.TsGen --version 8.2.0
                    
NuGet\Install-Package Asgard.TsGen -Version 8.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Asgard.TsGen" Version="8.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asgard.TsGen" Version="8.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Asgard.TsGen" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Asgard.TsGen --version 8.2.0
                    
#r "nuget: Asgard.TsGen, 8.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Asgard.TsGen@8.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Asgard.TsGen&version=8.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Asgard.TsGen&version=8.2.0
                    
Install as a Cake Tool

Asgard.TsGen

Asgard.TsGen 是面向 Asgard 项目的 TypeScript 代码生成组件。它会扫描带有 AsgardTsGenAttribute 的 ASP.NET Core 控制器与相关模型,并生成可直接在前端项目中使用的 TypeScript 请求层与类型定义。

可以在业务代码中直接调用 ITsGenerationService / TsGenerationService,也可以由 Yggdrasil 宿主按需开放开发环境导出端点。

主要能力

  • 根据 Asgard 控制器定义生成前端请求函数。
  • 同步生成接口入参与返回值对应的 TypeScript 类型。
  • 支持路由、查询、请求头和表单绑定别名。
  • 支持多表单字段、文件上传、文件下载和 SSE。
  • 支持 Task、ValueTask、统一响应、分页响应和游标响应。
  • 对控制器、Action 和模型重名进行稳定消歧。
  • 支持在 CI 或本地代码中调用生成服务,减少手写与维护成本。

安装

dotnet add package Asgard.TsGen

使用示例

using Asgard.TsGen;

var generationService = new TsGenerationService();

await generationService.GenerateAsync(
    new TsGenOptions
    {
        Assembly = typeof(Program).Assembly,
        OutputDirectory = "./generated/ts",
        RequestImportPath = "@/services/request"
    });

使用 Yggdrasil 宿主时,可以通过 host.tsGen.enabled: true 启用开发环境导出端点,并访问 /asgard-tsgen 下载生成结果。

生成结果

  • common/request.ts:公共请求封装引用入口。
  • common/response.ts:通用响应模型定义。
  • controller/*.ts:按控制器拆分的请求方法。
  • models/<ControllerName>/index.ts:控制器关联的 TypeScript 类型定义。

配置说明

  • Assembly:待扫描的程序集。
  • ControllerTypes:可选,显式指定需要生成的控制器类型集合。
  • OutputDirectory:生成文件输出目录。
  • RequestImportPath:请求封装的导入路径,例如 @/services/request。

注意事项

  • 只有带有生成标记的控制器和模型才会进入输出结果。
  • 如果指定了 ControllerTypes,则只会处理该集合中的控制器。
  • 每次生成都会删除并重建输出目录下的 common/、controller/、models/;这三个目录必须保持为纯生成目录。
  • 输出根目录中的其他文件不会被删除。
  • 遇到不受支持的返回契约时生成器会明确失败,不会输出猜测性的错误客户端。
  • TsGen 是可选能力;不使用生成客户端的项目无需添加 [AsgardTsGen],也无需启用宿主导出端点。
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Asgard.TsGen:

Package Downloads
Asgard.Yggdrasil.AspNetCore

Asgard.Yggdrasil.AspNetCore 是 Asgard 框架的 ASP.NET Core 主机层,集成 OpenAPI、Scalar、数据保护、日志和核心服务。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.2.0 60 11/20/2026
8.1.0 60 11/19/2026
8.0.0 56 11/19/2026
7.2.0 84 11/17/2026
7.1.0 93 11/17/2026
7.0.0 112 11/13/2026
6.1.0 135 11/6/2026
6.0.4 158 10/24/2026
6.0.3 163 10/11/2026
6.0.2 136 10/8/2026
6.0.1 126 10/8/2026
6.0.0 134 10/1/2026
5.3.0 189 10/1/2026
5.2.3 133 10/1/2026
5.2.2 149 9/1/2026
5.2.1 142 8/26/2026
5.2.0 247 8/6/2026
5.1.5 152 8/4/2026
5.1.4 159 8/3/2026
5.1.3 154 7/26/2026
Loading failed