一、文件夹\项目结构1.1、文件夹
文章插图
net6.0:针对.net 6.0 项目模板
net6.0pack:针对net6.0打包
1.2、项目结构
文章插图
Web\WebApi多项目、各层项目、单元测试项目
目标:制作Web\WebApi两个项目模板
二、模板参数2.1、template\net6.0\.template.config\template.json{ "$schema": "http://json.schemastore.org/template", "author": "yinyunpan", "classifications": [ "Web", "WebApi" ], "name": "项目模板案例", "identity": "sample.template", "shortName": "st", "tags": { "language": "C#", //解决方案 , 与HostIdentifier用法生成解决方案文件名呼应 "type": "solution" }, "sourceName": "sampletemplate", "preferNameDirectory": false, //重新生成项目guid , 对应template.sln中项目guid "guids": [ "5A6E6B9F-F8FA-4152-95B4-860F8CCAE3C3", "30B12CFC-11E1-4E1C-B484-F708CEBD080A", "810CD02B-0E13-4123-A84F-FBD4F4F1CD3A", "3D2A540B-E773-44FA-82CF-14F3393D41B2", "F4C1EFA8-824C-4985-A50D-BD1171ED1CFC", "41C74675-6234-41F2-9B8A-4D06159D2A81", "5EAD3BC3-554B-4058-9A9D-A91DF5F2DE1C", "8A522BE9-0EE5-4C54-861B-394452A6744E", "F075845E-43F4-466D-B731-904782BD9047" ], "symbols": { /** template.sln文件有用host,排除项目文件引用 modifiers-condition , 排除文件夹+文件 **/ "host": { "type": "parameter", "datatype": "choice", "choices": [ { "choice": "web", "description": "后台" }, { "choice": "webapi", "description": "接口" } ], "defaultValue": "web", "description": "项目类型", "displayName": "项目类型", "isRequired": true }, "web": { "type": "computed", "value": "(host == \"web\")" }, "webapi": { "type": "computed", "value": "(host == \"webapi\")" }, //应用的环境变量 "appUK": { "type": "parameter", "datatype": "string", "description": "应用标识", "displayName": "应用标识", "isRequired": true, "replaces": "wutong.netcore.sampletemplate" }, "kestrelHttpPort": { "type": "parameter", "datatype": "integer", "description": "启动配置文件的http端口", "displayName": "http端口" }, "kestrelHttpPortGenerated": { "type": "generated", "generator": "port", "parameters": { "low": 5000, "high": 5300 } }, "kestrelHttpPortReplacer": { "type": "generated", "generator": "coalesce", "parameters": { "sourceVariableName": "kestrelHttpPort", "fallbackVariableName": "kestrelHttpPortGenerated" }, //与launchSettings.json端口一致,才能随机生成替换 "replaces": "5000" }, //模板主机标识 "HostIdentifier": { "type": "bind", "binding": "HostIdentifier" } }, "sources": [ { "exclude": [ ".template.config/**/*", ".vs/**/*" ], "modifiers": [ { "condition": "(web)", "exclude": [ "src/WebApi/**/*", "test/WebApiUnitTest/**/*" ] }, { "condition": "(webapi)", "exclude": [ "src/Web/**/*", "test/WebUnitTest/**/*" ] }, { /** visual studio创建模板会自动生成新的解决方案文件.sln、与模板下{sourceName}.sln冲突,导致生成visual studio提醒外部文件变化重新加载,操作不友好 判断使用模板主机标识:vs-visual studio、dotnetcli\dotnetcli-preview-命令窗口 模板下解决方案文件名要非{sourceName}.sln,命令窗口重命名 参考:https://github.com/sayedihashimi/template-sample/tree/main/src/Samples/06-console-csharp-fsharp **/ "condition": "(HostIdentifier == \"dotnetcli\" || HostIdentifier == \"dotnetcli-preview\")", "rename": { "template.sln": "sampletemplate.sln" } } ] } ]}
推荐阅读
- 上 学习ASP.NET Core Blazor编程系列六——新增图书
- Azure DevOps Pipelines部署.Net Core 应用到Kubernetes
- C语言小白刷题
- AspNetCore中 使用 Grpc 简单Demo
- 插件化编程之WebAPI统一返回模型
- 使用EF Core更新与修改生产数据库
- .Net WebApi 中的 FromBody FromForm FromQuery FromHeader FromRoute
- 18 基于.NetCore开发博客项目 StarBlog - 实现本地Typora文章打包上传
- JavaWeb505错误,IDEA版问题解决
- 结合springboot实现,这里对接的是easy版本,工具用的是IDEA,WebStrom 支付宝沙箱服务