Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit eeb7646

Browse files
committed
Use branch naming for versioning releases
1 parent 37bc459 commit eeb7646

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

GitInfo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0-dev

build.proj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<CommonBuildProperties>WarningLevel=0;NoWarn=1591;Out=$(Out);Configuration=$(Configuration);RunCodeAnalysis=$(RunCodeAnalysis);PackageOutputPath=$(Out)</CommonBuildProperties>
2020
<DefaultImportance Condition=" '$(DefaultImportance)' == '' ">high</DefaultImportance>
2121
<PS>%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PS>
22+
<GitInfoReportImportance>high</GitInfoReportImportance>
2223
</PropertyGroup>
2324

2425
<ItemGroup>
@@ -140,8 +141,8 @@
140141
<GitSemVerPatch>0</GitSemVerPatch>
141142
</PropertyGroup>
142143
</Target>
143-
<Import Project="$(GitInfoTargets)" Condition="Exists('$(GitInfoTargets)')"/>
144144
<Import Project="src\PackageVersion.targets" />
145+
<Import Project="$(GitInfoTargets)" Condition="Exists('$(GitInfoTargets)')"/>
145146

146147
<Target Name="Configure" DependsOnTargets="DownloadNuGet;GetPackageVersion">
147148
<Message Importance="high" Text="*********************************************************************************************************************" />
@@ -152,11 +153,10 @@
152153
StandardOutputImportance="low"
153154
Condition=" '$(PendingRestore)' == 'true' " />
154155

155-
<!-- Invoke GitVersion just like the project-level targets do -->
156-
<MSBuild Projects="$(GitInfoTargets)" Targets="GitVersion;GitInfoReport" Properties="GitInfoReportImportance=high">
157-
<Output TaskParameter="TargetOutputs" ItemName="GitInfo" />
158-
</MSBuild>
156+
<Error Text="Build script NuGet packages were missing and were just restored. Please run the build again." Condition=" '$(PendingRestore)' == 'true' "/>
159157

158+
<!-- Invoke GitVersion just like the project-level targets do -->
159+
<CallTarget Targets="GitInfoReport" />
160160
<!-- For now this is an informative version #, used to update CI -->
161161
<Message Text="Building version $(PackageVersion)" Importance="high" />
162162

src/PackageVersion.targets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup>
5-
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
6+
<!-- We use branch and file version sources only -->
7+
<GitIgnoreTagVersion>true</GitIgnoreTagVersion>
68
<BuildDependsOn>
79
GetPackageVersion;
810
$(BuildDependsOn)
@@ -11,13 +13,19 @@
1113

1214
<Target Name="GetPackageVersion" BeforeTargets="ThisProjectInfo" DependsOnTargets="GitVersion" Returns="$(PackageVersion)">
1315
<PropertyGroup>
14-
<GitSemVerDashLabel Condition="'$(GitBranch)' == 'undefined'">-pr</GitSemVerDashLabel>
16+
<!-- PR builds are *always* prerelease -->
17+
<!-- TFS case: BUILD_REASON=PullRequest and BUILD_SOURCEBRANCH=refs/pull/[#]/merge -->
18+
<GitSemVerDashLabel Condition="'$(TF_BUILD)' == 'true' and '$(BUILD_REASON)' == 'PullRequest'">-pr$(BUILD_SOURCEBRANCH.Substring(10).TrimEnd('/merge'))</GitSemVerDashLabel>
1519
<GitSemVerDashLabel Condition="'$(APPVEYOR_PULL_REQUEST_NUMBER)' != ''">-pr$(APPVEYOR_PULL_REQUEST_NUMBER)</GitSemVerDashLabel>
16-
<PackageVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageVersion>
20+
21+
<!-- Non-prerelease versions will use the package version determined by SemVer -->
22+
<PackageVersion Condition="'$(GitSemVerDashLabel)' == ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</PackageVersion>
23+
<!-- Prerelease versions are fixed to the base version (this allows the stable versions to always be greater) and have the build number instead -->
24+
<PackageVersion Condition="'$(GitSemVerDashLabel)' != ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitBaseVersionPatch)$(GitSemVerDashLabel)-build$(GitCommits.PadLeft(4, '0'))</PackageVersion>
1725
</PropertyGroup>
1826
</Target>
1927

2028
<PropertyGroup>
2129
<PackageVersionImported>true</PackageVersionImported>
2230
</PropertyGroup>
23-
</Project>
31+
</Project>

0 commit comments

Comments
 (0)