Net通用應用的專案框架腳手架

风骚小王子發表於2024-03-18
說明
通用應用的專案框架腳手架
介紹
1、新建模板專案的資料夾Tpl,並在該資料夾下面新建templates檔案
2、將我們需要打包的專案放到templates中
3、在templates中新建.template.config資料夾
4、在.template.config資料夾中新建template.json檔案
5、在template.json檔案中填寫下列內容
{ "$schema": "http://json.schemastore.org/template", "author": "pp", "classifications": [ "xxx.Api" ], "name": "xxx.Api",//必須,對應模板名稱 "identity": "xxx.Api",//可選,模板的唯一名稱 "shortName": "zz",//必須,用於透過該指令生成專案 "tags": { "language": "C#", "type": "project" }, "sourceName": "xxx.Api",// 可選,要替換的專案名字 "preferNameDirectory": true }
6、在Tpl資料夾下新建template-pack.csproj檔案,並填寫下列內容
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <PackageType>xxx.Api</PackageType> <PackageVersion>1.1.2</PackageVersion> <PackageId>xxx.Api</PackageId> <Title>xxx.Api</Title> <Authors>pp</Authors> <Description>xxx.Api</Description> <PackageTags>dotnet-new;templates;xxx.Api</PackageTags> <TargetFrameworks>net6.0;net7.0</TargetFrameworks> <IncludeContentInPack>true</IncludeContentInPack> <IncludeBuildOutput>false</IncludeBuildOutput> <ContentTargetFolders>content</ContentTargetFolders> <NoWarn>$(NoWarn);NU5128</NoWarn> </PropertyGroup> <ItemGroup> <Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" /> <Compile Remove="**\*" /> </ItemGroup> </Project>
7、雙擊開啟template-pack.csproj,並打包生成對應的nuget包
8、上傳該包至nuget上
dotnet nuget push -s http://localhost:8020/v3/index.json xxx.nupkg -k xxx
9、本地安裝該nuget包
dotnet new install xxx.Api
如果是http等私有協議的:需要透過--force查詢不安全的源即http協議的源服務
dotnet new install --force xxx.Api
10、透過腳手架新建專案
dotnet new zz -n="HHH"
11、執行該專案,相關內容已經全部初始化完成

相關文章