forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersioning.targets
80 lines (67 loc) · 3.99 KB
/
Versioning.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<_BuildNumber>$(OfficialBuildId)</_BuildNumber>
<_BuildNumber Condition="'$(OfficialBuildId)' == ''">$([System.DateTime]::Now.ToString(yyyyMMdd)).1</_BuildNumber>
<HasReleaseVersion>true</HasReleaseVersion>
<HasReleaseVersion Condition="$(Version.Contains('preview')) or $(Version.Contains('beta'))">false</HasReleaseVersion>
<_VersionInProject>$(Version)</_VersionInProject>
</PropertyGroup>
<PropertyGroup Condition="'$(SkipDevBuildNumber)' != 'true'">
<!-- Strip off the prerelease version -->
<_PrereleaseIndex>$(Version.IndexOf('-'))</_PrereleaseIndex>
<Version Condition="$(_PrereleaseIndex) > 0">$(Version.SubString(0, $(_PrereleaseIndex)))</Version>
<Version>$(Version)-alpha.$(_BuildNumber)</Version>
</PropertyGroup>
<!--
Specification: https://github.com/dotnet/arcade/blob/master/Documentation/CoreVersioning.md
File version has 4 parts and needs to increase every official build. This is especially important when building MSIs.
FILEMAJOR.FILEMINOR.FILEPATCH.FILEREVISION
FILEMAJOR: Specified in the first part of VersionPrefix property.
FILEMINOR: Set to MINOR * 100 + PATCH / 100, where MINOR and PATCH are the 2nd and 3rd parts of VersionPrefix property.
FILEPATCH: Set to (PATCH % 100) * 100 + yy.
FILEREVISION: Set to (50 * mm + dd) * 100 + r. This algorithm makes it easy to parse the month and date from FILEREVISION while staying in the range of a short which is what a version element uses.
The versioning scheme defined below imposes the following limits on these version parts:
- `MAJOR` version is in range [0-65535]
- `MINOR` version is in range [0-654]
- `PATCH` version is in range [0-9999]
-->
<Target Name="_InitializeFileVersion" BeforeTargets="GetAssemblyVersion">
<Error Text="Expected _BuildNumber to match OfficialBuildId property!"
Condition="'$(OfficialBuildId)' != '' and '$(OfficialBuildId)' != '$(_BuildNumber)'" />
<Error Text="Invalid format of OfficialBuildId: '$(OfficialBuildId)' should be in form yyyyMMdd.r"
Condition="$(OfficialBuildId) != '' and ($(OfficialBuildId.Length) < 10 or '$(OfficialBuildId[8])' != '.')" />
<!-- Compute an ever increasing build number based on official build id assuming it is passed -->
<PropertyGroup Condition="'$(OfficialBuildId)' != ''">
<_BuildNumberYY>$(_BuildNumber.Substring(2, 2))</_BuildNumberYY>
<_BuildNumberMM>$(_BuildNumber.Substring(4, 2))</_BuildNumberMM>
<_BuildNumberDD>$(_BuildNumber.Substring(6, 2))</_BuildNumberDD>
<_BuildNumberR>$(_BuildNumber.Substring(9))</_BuildNumberR>
<_VersionPrefixMajor>$(Version.Split('.')[0])</_VersionPrefixMajor>
<_VersionPrefixMinor>$(Version.Split('.')[1])</_VersionPrefixMinor>
<_VersionPrefixPatch>$(Version.Split(".-")[2])</_VersionPrefixPatch>
<_FileMajor>$(_VersionPrefixMajor)</_FileMajor>
<!-- MINOR * 100 + PATCH / 100 -->
<_FileMinor>$([MSBuild]::Add(
$([MSBuild]::Multiply($(_VersionPrefixMinor), 100)),
$([System.Convert]::ToInt32($([MSBuild]::Divide($(_VersionPrefixPatch), 100))))
))</_FileMinor>
<!-- (PATCH % 100) * 100 + yy -->
<_FilePatch>$([MSBuild]::Add(
$([MSBuild]::Multiply(
$([MSBuild]::Modulo($(_VersionPrefixPatch), 100)),
100)),
$(_BuildNumberYY)
))</_FilePatch>
<!-- mm * 5000 + dd * 100 + r -->
<_FileRevision>$([MSBuild]::Add(
$([MSBuild]::Add(
$([MSBuild]::Multiply($(_BuildNumberMM), 5000)),
$([MSBuild]::Multiply($(_BuildNumberDD), 100))
)),
$(_BuildNumberR)
))</_FileRevision>
<FileVersion>$(_FileMajor).$(_FileMinor).$(_FilePatch).$(_FileRevision)</FileVersion>
</PropertyGroup>
</Target>
</Project>