-
Notifications
You must be signed in to change notification settings - Fork 12
/
GitVersion.Targets
81 lines (66 loc) · 3.83 KB
/
GitVersion.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
81
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(PkgMSBuildTasks)\tools\MSBuild.Community.Tasks.Targets" Condition="Exists('$(PkgMSBuildTasks)\tools\MSBuild.Community.Tasks.Targets')" />
<Target Name="CreateVersionInfo" BeforeTargets="CoreCompile">
<GitDescribe>
<Output TaskParameter="Tag" PropertyName="GitTag" />
<Output TaskParameter="CommitHash" PropertyName="GitCommitHash" />
<Output TaskParameter="CommitCount" PropertyName="GitCommitCount" />
</GitDescribe>
<GitCommitDate Format="yyyy">
<Output TaskParameter="CommitDate" PropertyName="CopyrightYear" />
</GitCommitDate>
<PropertyGroup>
<MajorVerPat>^v?([0-9]+).*$</MajorVerPat>
<MinorVerPat>^v?[0-9]+[.]([0-9]+).*$</MinorVerPat>
<PatchVerPat>^v?[0-9]+[.][0-9]+[.]([0-9]+).*$</PatchVerPat>
<TruncGitHashPat>^([a-z0-9]{8}).*$</TruncGitHashPat>
</PropertyGroup>
<RegexReplace Input="$(GitTag)" Expression="$(MajorVerPat)" Replacement="TRUE">
<Output TaskParameter="Output" PropertyName="HasMajorVer" />
</RegexReplace>
<RegexReplace Input="$(GitTag)" Expression="$(MajorVerPat)" Replacement="$1" Condition="$(HasMajorVer)=='TRUE'">
<Output TaskParameter="Output" PropertyName="MajorVer" />
</RegexReplace>
<RegexReplace Input="$(GitTag)" Expression="$(MinorVerPat)" Replacement="TRUE">
<Output TaskParameter="Output" PropertyName="HasMinorVer" />
</RegexReplace>
<RegexReplace Input="$(GitTag)" Expression="$(MinorVerPat)" Replacement="$1" Condition="$(HasMinorVer)=='TRUE'">
<Output TaskParameter="Output" PropertyName="MinorVer" />
</RegexReplace>
<RegexReplace Input="$(GitTag)" Expression="$(PatchVerPat)" Replacement="TRUE">
<Output TaskParameter="Output" PropertyName="HasPatchVer" />
</RegexReplace>
<RegexReplace Input="$(GitTag)" Expression="$(PatchVerPat)" Replacement="$1" Condition="$(HasPatchVer)=='TRUE'">
<Output TaskParameter="Output" PropertyName="PatchVer" />
</RegexReplace>
<RegexReplace Input="$(GitCommitHash)" Expression="$(TruncGitHashPat)" Replacement="TRUE">
<Output TaskParameter="Output" PropertyName="HasTruncGitHash" />
</RegexReplace>
<RegexReplace Input="$(GitCommitHash)" Expression="$(TruncGitHashPat)" Replacement="$1" Condition="$(HasTruncGitHash)=='TRUE'">
<Output TaskParameter="Output" PropertyName="TruncGitHash" />
</RegexReplace>
<PropertyGroup>
<MajorVer Condition="'$(MajorVer)'==''">0</MajorVer>
<MinorVer Condition="'$(MinorVer)'==''">0</MinorVer>
<PatchVer Condition="'$(PatchVer)'==''">0</PatchVer>
<GitTag Condition="'$(GitTag)'==''">?.?</GitTag>
<GitCommitCount Condition="'$(GitCommitCount)'==''">0</GitCommitCount>
<TruncGitHash Condition="'$(TruncGitHash)'==''">Unknown</TruncGitHash>
<CopyrightYear Condition="'$(CopyrightYear)'==''">0000</CopyrightYear>
<InfoVersion>$(GitTag)-$(TruncGitHash)</InfoVersion>
<InfoVersion Condition="'$(GitCommitCount)'!='0'">$(GitTag)-$(GitCommitCount)-$(TruncGitHash)</InfoVersion>
</PropertyGroup>
<ReadLinesFromFile File="$(IntermediateOutputPath)lastcommit.txt">
<Output TaskParameter="Lines" PropertyName="LastCommit"/>
</ReadLinesFromFile>
<AssemblyInfo Condition="'$(GitCommitHash)'!='$(LastCommit)'"
CodeLanguage="CS" OutputFile="Properties\VersionInfo.cs"
AssemblyVersion="$(MajorVer).$(MinorVer).$(PatchVer).0"
AssemblyFileVersion="$(MajorVer).$(MinorVer).$(PatchVer).$(GitCommitCount)"
AssemblyInformationalVersion="$(InfoVersion)"
AssemblyCopyright="Copyright © 2007-$(CopyrightYear)" />
<WriteLinesToFile File="$(IntermediateOutputPath)lastcommit.txt"
Lines="$(GitCommitHash)" Overwrite="true" />
</Target>
</Project>