Asgard.TsGen
5.2.2
dotnet add package Asgard.TsGen --version 5.2.2
NuGet\Install-Package Asgard.TsGen -Version 5.2.2
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="5.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asgard.TsGen" Version="5.2.2" />
<PackageReference Include="Asgard.TsGen" />
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 5.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Asgard.TsGen, 5.2.2"
#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@5.2.2
#: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=5.2.2
#tool nuget:?package=Asgard.TsGen&version=5.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Asgard.Abstractions (>= 5.2.2)
- Asgard.Abstractions.AspNetCore (>= 5.2.2)
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 主机层,提供完整的 Web 应用程序启动模板,集成了Swagger、数据保护、日志和所有核心服务,帮助快速构建模块化应用。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.2.2 | 118 | 9/1/2026 |
| 5.2.1 | 121 | 8/26/2026 |
| 5.2.0 | 211 | 8/6/2026 |
| 5.1.5 | 127 | 8/4/2026 |
| 5.1.4 | 139 | 8/3/2026 |
| 5.1.3 | 133 | 7/26/2026 |
| 5.1.2 | 177 | 7/20/2026 |
| 5.1.1 | 136 | 7/20/2026 |
| 5.1.0 | 135 | 7/20/2026 |
| 5.0.3 | 135 | 7/15/2026 |
| 5.0.2 | 137 | 7/15/2026 |
| 5.0.1 | 137 | 7/8/2026 |
| 4.1.11 | 155 | 6/30/2026 |
| 4.1.10 | 137 | 6/28/2026 |
| 4.1.9 | 155 | 6/7/2026 |
| 4.1.8 | 379 | 5/31/2026 |
| 4.1.7 | 149 | 5/24/2026 |
| 4.1.6 | 147 | 5/24/2026 |
| 4.1.5 | 141 | 5/23/2026 |
| 4.1.4 | 139 | 5/16/2026 |
Loading failed