asp.net core web 解決方案多項目模板制作打包總結

一、文件夾\項目結構1.1、文件夾

asp.net core web 解決方案多項目模板制作打包總結

文章插圖
net6.0:針對.net 6.0 項目模板
net6.0pack:針對net6.0打包
1.2、項目結構
asp.net core web 解決方案多項目模板制作打包總結

文章插圖
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"          }        }      ]    }  ]}

推薦閱讀