Asgard.TsGen
4.0.5
dotnet add package Asgard.TsGen --version 4.0.5
NuGet\Install-Package Asgard.TsGen -Version 4.0.5
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="4.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asgard.TsGen" Version="4.0.5" />
<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 4.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Asgard.TsGen, 4.0.5"
#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@4.0.5
#: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=4.0.5
#tool nuget:?package=Asgard.TsGen&version=4.0.5
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 之外,也可以结合 dotnet tool 或宿主集成方式,在构建流程中自动生成前端所需的接口代码。
主要能力
- 根据 Asgard 控制器定义生成前端请求函数。
- 同步生成接口入参与返回值对应的 TypeScript 类型。
- 支持在 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",
Overwrite = true
});
生成结果
common/request.ts:公共请求封装引用入口。common/response.ts:通用响应模型定义。controller/*.ts:按控制器拆分的请求方法。models/<ControllerName>/index.ts:控制器关联的 TypeScript 类型定义。
配置说明
Assembly:待扫描的程序集。ControllerTypes:可选,显式指定需要生成的控制器类型集合。OutputDirectory:生成文件输出目录。RequestImportPath:请求封装的导入路径,例如@/services/request。Overwrite:是否覆盖已存在文件,通常建议设为true。
注意事项
- 只有带有生成标记的控制器和模型才会进入输出结果。
- 如果指定了
ControllerTypes,则只会处理该集合中的控制器。 - 建议在前端仓库或宿主构建流程中固定输出目录,避免生成文件分散。
| 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 (>= 4.0.5)
- Asgard.Abstractions.AspNetCore (>= 4.0.5)
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.