今天想研究的是如何透過自動化的方式去設定專案的版本號,預期會是與 Git 做掛鉤。
首先,先安裝 GitVersionTask 這個套件:
$ dotnet add package GitVersionTask --version 5.0.1
Writing /var/folders/hx/lgdjx1l93pq08s35hhwb0py40000gn/T/tmpSIIyRn.tmp
info : Adding PackageReference for package 'GitVersionTask' into project '/Users/ironman/dotnet-sln/WebProj/WebProj.csproj'.
info : Restoring packages for /Users/ironman/dotnet-sln/WebProj/WebProj.csproj...
info : GET https://api.nuget.org/v3-flatcontainer/gitversiontask/index.json
info : OK https://api.nuget.org/v3-flatcontainer/gitversiontask/index.json 934ms
info : GET https://api.nuget.org/v3-flatcontainer/gitversiontask/5.0.1/gitversiontask.5.0.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/gitversiontask/5.0.1/gitversiontask.5.0.1.nupkg 1119ms
info : Installing GitVersionTask 5.0.1.
info : Package 'GitVersionTask' is compatible with all the specified frameworks in project '/Users/ironman/dotnet-sln/WebProj/WebProj.csproj'.
info : PackageReference for package 'GitVersionTask' version '5.0.1' added to file '/Users/ironman/dotnet-sln/WebProj/WebProj.csproj'.
info : Committing restore...
info : Generating MSBuild file /Users/ironman/dotnet-sln/WebProj/obj/WebProj.csproj.nuget.g.props.
info : Generating MSBuild file /Users/ironman/dotnet-sln/WebProj/obj/WebProj.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/ironman/dotnet-sln/WebProj/obj/project.assets.json
log : Restore completed in 7.47 sec for /Users/ironman/dotnet-sln/WebProj/WebProj.csproj.
然後在 Repository 根目錄下建立 GitVersion.yml
依照我們要的方式進行設定:
next-version: 1.0
mode: ContinuousDelivery
increment: Inherit
tag-prefix: '[vV]'
source-branches: ['master', 'feature', 'hotfix']
ignore:
sha: []
commits-before: 2019-09-29T00:00:00
branches:
master:
regex: master$
mode: ContinuousDelivery
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: true
release:
regex: releases/
mode: ContinuousDelivery
tag: beta
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
tracks-release-branches: false
is-release-branch: true
feature:
regex: features/
mode: ContinuousDeployment
tag: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
先記錄到這邊,預計明天會把設定檔的概念補上來。