Skip to content

新建App业务端项目 9.0.0

安装或升级模板

cs
dotnet new install ZhonTai.Template.App

升级模板命令和安装模板命令相同

注意

如果已安装ZhonTai.Template模板,需要先卸载模板再安装ZhonTai.Template.App,避免模板短名称MyApp冲突

cs
dotnet new uninstall ZhonTai.Template

安装指定版本

cs
dotnet new install ZhonTai.Template.App::9.0.5

查看帮助

cs
dotnet new MyApp -h
[模板选项]
-at, --app-type <app|mem|sys>         
  根据项目需求选择不同的类别
  类型: choice
    sys  包含Admin接口,适用于平台端开发,具备登录、数据权限和功能权限限制。
    app  不含Admin接口,需要Grpc和Http远程通讯,适用于租户端开发,具备登录、数据权限和功能权限限制。
    mem  适用于用户端或会员端开发,不依赖Admin接口,需要Grpc和Http远程通讯,
         具备登录、数据权限限制,无功能权限限制。
  默认: app
-ac, --app-code <app-code>             可选,不填默认使用app-type项目类别选项
  用于在项目中唯一地标识不同的功能模块,以便于管理和区分,如 sys | biz | mem。
  类型: string
-p, --port <port>                      
  设置接口项目启动时所监听的端口号,如 18010 | 18020 | 18030。
  必需: true
  类型: int
-gp, --grpc-port <grpc-port>           
  配置GRPC远程通讯所使用的端口号,建议设置为Http端口加1,如 18011 | 18021 | 18031。
  必需: true
  类型: int
-sk, --security-key <security-key>     可选,不填默认使用Guid生成
  设置jwtconfig.securityKey的值,用于JWT令牌的安全验证,确保接口调用的安全性。
  启用条件: AppType == sys
  类型: string
-db, --db-type <MySql|PostgreSQL|...>  
  根据项目需求选择合适的数据库类型,支持国内外主流数据库。
  类型: choice
    MySql       MySql
    PostgreSQL  PostgreSQL
    SqlServer   SqlServer
    Oracle      Oracle
    Sqlite      Sqlite
    Firebird    Firebird
    MsAccess    MsAccess
    Dameng      达梦数据库,提供稳定可靠的数据存储和查询服务。
    ShenTong    神通数据库,具备高性能和可扩展性,满足复杂业务需求。
    KingbaseES  人大金仓数据库,提供全面的数据管理和安全保护。
    Gbase       南大通用数据库,支持大规模数据处理和分析。
    ClickHouse  ClickHouse
    QuestDb     QuestDb
    Xugu        虚谷数据库,提供灵活的数据存储和高效的查询性能。
  默认: Sqlite
-nau, --no-apiui                       
  选择此项将不使用新版接口文档功能,减少不必要的资源占用。
  类型: bool
  默认: false
-nts, --no-task-scheduler              
  选择此项将不集成任务调度服务,适用于无需定时任务处理的项目。
  类型: bool
  默认: false
-nc, --no-cap                          
  选择此项将不使用CAP分布式事务和事件总线功能,降低系统复杂性。
  类型: bool
  默认: false
-nt, --no-tests                        
  选择此项将不会生成测试数据库,适用于无需进行自动化测试的项目。
  类型: bool
  默认: false
-ns, --no-sample                       
  选择此项将不会生成默认的模块代码及其相关文件,适用于已熟悉开发流程并希望快速进入开发阶段的开发者。
  类型: bool
  默认: false
-md, --merge-db                        
  选择此项将会将admindb数据库合并到appdb中,实现数据库资源的统一管理和维护。
  类型: bool
  默认: false

查看已安装模板

cs
dotnet new list

卸载模板

cs
dotnet new uninstall ZhonTai.Template.App

新建平台端项目

  • 设置项目编码和端口号
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 18010 -gp 18011
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -p 16010 -gp 16011
  • 切换数据库为MySql
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 18010 -gp 18011 -db MySql
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 16010 -gp 16011 -db MySql
  • 将权限数据库admindb合并到业务库appdb中,同时切换数据库为MySql
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 18010 -gp 18011 -md true -db MySql
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 16010 -gp 16011 -md true -db MySql
  • 🔥多模块开发时,已熟悉怎么开发不想要模块示例,不想增加测试库,可以这样配置 8.3.0
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 18010 -gp 18011 -nt true -ns true
cs
dotnet new MyApp -n MyCompanyName.MySys -at sys -ac sys -p 16010 -gp 16011 -nt true -ns true

新建业务端项目

  • 设置项目编码和端口号
cs
dotnet new MyApp -n MyCompanyName.MyBiz -at app -ac biz -p 18020 -gp 18021
  • 切换数据库为MySql
cs
dotnet new MyApp -n MyCompanyName.MyBiz -at app -ac biz -p 18020 -gp 18021 -db MySql
  • 🔥多模块开发时,已熟悉怎么开发不想要模块示例,不想增加测试库,可以这样配置 8.3.0
cs
dotnet new MyApp -n MyCompanyName.MyBiz -at app -ac biz -p 18020 -gp 18021 -nt true -ns true

新建用户端项目

  • 设置项目编码和端口号
cs
dotnet new MyApp -n MyCompanyName.MyMem -at mem -ac mem -p 18030 -gp 18031
  • 切换数据库为MySql
cs
dotnet new MyApp -n MyCompanyName.MyMem -at mem -ac mem -p 18030 -gp 18031 -db MySql
  • 🔥多模块开发时,已熟悉怎么开发不想要模块示例,不想增加测试库,可以这样配置 8.3.0
cs
dotnet new MyApp -n MyCompanyName.MyMem -at mem -ac mem -p 18030 -gp 18031 -nt true -ns true

使用Tye运行&调试模块项目

1、安装Tye

dotnet tool install -g Microsoft.Tye --version "0.12.0-*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json

2、运行&调试

  1. vs安装拓展EasyRun
  2. 打开VS的 视图-> 其他窗口 -> EasyRun,点击打开EasyRun窗口
  3. 配置EasyRun
EasyRun配置参考
{
  "SettingsId": "2b14968a-f3ca-4849-bcad-5d4f210d2960",
  "Profiles": [
    {
      "Name": "Default",
      "LoggingTargetType": 0,
      "LoggingPath": "./.logs",
      "LoggerUrl": null,
      "UseTye": true,
      "TyePort": 10000,
      "Filter": ".Host",
      "Services": [
        {
          "ServiceType": 0,
          "Name": "MyCompanyName.MyGateway.Host",
          "TyeName": null,
          "ProjectFile": "gateways\\MyCompanyName.MyGateway\\MyCompanyName.MyGateway.Host.csproj",
          "DefaultSelected": true,
          "Bindings": "::16010",
          "Arguments": null,
          "EnvVariables": null,
          "Replicas": 1
        },
        {
          "ServiceType": 0,
          "Name": "MyCompanyName.MyIMServer.Host",
          "TyeName": null,
          "ProjectFile": "modules\\im\\MyCompanyName.MyIMServer\\MyCompanyName.MyIMServer.Host.csproj",
          "DefaultSelected": true,
          "Bindings": "::17010",
          "Arguments": null,
          "EnvVariables": null,
          "Replicas": 1
        },
        {
          "ServiceType": 0,
          "Name": "MyCompanyName.MySys",
          "TyeName": null,
          "ProjectFile": "modules\\sys\\MyCompanyName.MySys\\MyCompanyName.MySys.Host.csproj",
          "DefaultSelected": true,
          "Bindings": "::18010",
          "Arguments": null,
          "EnvVariables": null,
          "Replicas": 1
        },
        {
          "ServiceType": 0,
          "Name": "MyCompanyName.MyBiz",
          "TyeName": null,
          "ProjectFile": "modules\\sys\\MyCompanyName.MyBiz\\MyCompanyName.MyBiz.Host.csproj",
          "DefaultSelected": true,
          "Bindings": "::18020",
          "Arguments": null,
          "EnvVariables": null,
          "Replicas": 1
        },
        {
          "ServiceType": 0,
          "Name": "MyCompanyName.MyMem",
          "TyeName": null,
          "ProjectFile": "modules\\sys\\MyCompanyName.MyMem\\MyCompanyName.MyMem.Host.csproj",
          "DefaultSelected": true,
          "Bindings": "::18030",
          "Arguments": null,
          "EnvVariables": null,
          "Replicas": 1
        }
      ]
    }
  ]
}
  1. 点击Tye按钮运行
  2. 选择要调试的微服务点击Debugger按钮开启调试

使用源码项目记得更改ZhonTai.Admin.Host/ConfigCenter/jwtconfig.json 配置文件的 securityKey 密钥

json
{
  "JwtConfig": {
    //密钥,注意字符串长度不能低于 32 位
    "securityKey": "33ce0d4b3a7b11ef8563526747b33ad4",
  }
}