1
+ namespace GitFlowVersionTask
2
+ {
3
+ using System ;
4
+ using GitFlowVersion ;
5
+ using Microsoft . Build . Framework ;
6
+ using Microsoft . Build . Utilities ;
7
+ using Logger = GitFlowVersion . Logger ;
8
+
9
+ public class GetVersion : Task
10
+ {
11
+
12
+ [ Required ]
13
+ public string SolutionDirectory { get ; set ; }
14
+
15
+ [ Output ]
16
+ public Stability ? Stability { get ; set ; }
17
+
18
+ [ Output ]
19
+ public int ? PreReleasePartTwo { get ; set ; }
20
+
21
+ [ Output ]
22
+ public int ? PreReleasePartOne { get ; set ; }
23
+
24
+ [ Output ]
25
+ public string SemVer { get ; set ; }
26
+
27
+ [ Output ]
28
+ public string Sha { get ; set ; }
29
+
30
+ [ Output ]
31
+ public string BranchType { get ; set ; }
32
+
33
+ [ Output ]
34
+ public string BranchName { get ; set ; }
35
+
36
+ [ Output ]
37
+ public string ShortVersion { get ; set ; }
38
+
39
+ [ Output ]
40
+ public string NugetVersion { get ; set ; }
41
+
42
+ [ Output ]
43
+ public string LongVersion { get ; set ; }
44
+
45
+ [ Output ]
46
+ public string Suffix { get ; set ; }
47
+
48
+ [ Output ]
49
+ public int Patch { get ; set ; }
50
+
51
+ [ Output ]
52
+ public int Minor { get ; set ; }
53
+
54
+ [ Output ]
55
+ public int Major { get ; set ; }
56
+
57
+ TaskLogger logger ;
58
+
59
+ public GetVersion ( )
60
+ {
61
+ logger = new TaskLogger ( this ) ;
62
+ Logger . WriteInfo = this . LogInfo ;
63
+ Logger . WriteWarning = this . LogWarning ;
64
+ }
65
+
66
+ public override bool Execute ( )
67
+ {
68
+ try
69
+ {
70
+ VersionAndBranch versionAndBranch ;
71
+ if ( VersionAndBranchFinder . TryGetVersion ( SolutionDirectory , out versionAndBranch ) )
72
+ {
73
+
74
+ Major = versionAndBranch . Version . Major ;
75
+ Minor = versionAndBranch . Version . Minor ;
76
+ Patch = versionAndBranch . Version . Patch ;
77
+ Suffix = versionAndBranch . Version . Suffix ;
78
+ LongVersion = versionAndBranch . ToLongString ( ) ;
79
+ NugetVersion = versionAndBranch . GenerateNugetVersion ( ) ;
80
+ ShortVersion = versionAndBranch . ToShortString ( ) ;
81
+ BranchName = versionAndBranch . BranchName ;
82
+ BranchType = versionAndBranch . BranchType == null ? null : versionAndBranch . BranchType . ToString ( ) ;
83
+ Sha = versionAndBranch . Sha ;
84
+ SemVer = versionAndBranch . GenerateSemVer ( ) ;
85
+ var releaseInformation = ReleaseInformationCalculator . Calculate ( versionAndBranch . BranchType , versionAndBranch . Version . Tag ) ;
86
+ PreReleasePartOne = releaseInformation . ReleaseNumber ;
87
+ PreReleasePartTwo = versionAndBranch . Version . PreReleasePartTwo ;
88
+ Stability = releaseInformation . Stability ;
89
+ }
90
+ return true ;
91
+ }
92
+ catch ( ErrorException errorException )
93
+ {
94
+ logger . LogError ( errorException . Message ) ;
95
+ return false ;
96
+ }
97
+ catch ( Exception exception )
98
+ {
99
+ logger . LogError ( "Error occurred: " + exception ) ;
100
+ return false ;
101
+ }
102
+ finally
103
+ {
104
+ Logger . Reset ( ) ;
105
+ }
106
+ }
107
+ }
108
+ }
0 commit comments