-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
GitInfo.targets
986 lines (842 loc) · 52.3 KB
/
GitInfo.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" InitialTargets="SetGitExe;GitSetVersion" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
==============================================================
Retrieves and exposes Git information.
If the importing project has a C#, F# or VB Language property, by default a ThisAssembly file/class will be generated containing assembly-level metadata for the git information,
as well as a ThisAssembly static class with constants for all the available values.
Customization:
$(GitVersion): set to 'false' to avoid setting Version and PackageVersion to a default version with format:
$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit)
$(GitThisAssembly): set to 'false' to prevent assembly metadata and constants generation.
$(GitThisAssemblyMetadata): set to 'false' to prevent assembly metadata generation only. Defaults to 'false'.
If 'true', it will also provide assembly metadata attributes for each of the populated values.
$(ThisAssemblyNamespace): allows overriding the namespace for the ThisAssembly class. Defaults to the global namespace.
$(GitRemote): name of remote to get repository url for. Defaults to 'origin'.
$(GitDefaultBranch): determines the base branch used to calculate commits on top of current branch. Defaults to 'main'.
$(GitBranchCI): determines whether the branch name should be populated from default environment variables used by the CI system. Default to 'true'.
$(GitVersionFile): determines the name of a file in the Git repository root used to provide the base version info. Defaults to 'GitInfo.txt'.
$(GitCommitsRelativeTo): optionally specifies an alternative directory for counting commits on top of the base version. Defaults to the $(GitVersionFile) directory.
$(GitCommitsIgnoreMerges): set to 'true' to ignore merge commits when calculating the number of commits. Defaults to 'false'.
$(GitInfoReportImportance): allows rendering all the retrieved git information with the specified message importance ('high', 'normal' or 'low'). Defaults to 'low'.
$(GitIgnoreBranchVersion) and $(GitIgnoreTagVersion): determines whether the branch and tags (if any) will be used to find a base version. Defaults to empty value (no ignoring).
$(GitNameRevOptions): options passed to git name-rev when finding a branch name for a commit (Detached head). The default is '--refs=refs/heads/* --no-undefined --always'
meaning branch names only, falling back to commit hash. For the legacy behavior where $(GitBranch) for detached head can also be a tag name, use '--refs=refs/*'.
Refs can be included and excluded, see git name-rev docs.
$(GitSkipCache): whether to cache the Git information determined in a previous build in a GitInfo.cache for performance reasons. Defaults to empty value (no ignoring).
$(GitCachePath): where to cache the determined Git information. Gives the chance to use a shared location for different projects. This can improve the overall build time.
Has to end with a path seperator Defaults to empty value ('$(IntermediateOutputPath)').
$(GitTagRegex): regular expression used with git describe to filter the tags to consider for base version lookup. Defaults to * (all).
$(GitBaseVersionRegex): regular expression used to match and validate valid base versions in branch, tag or file sources. By default, matches any string that *ends* in a valid SemVer2 string.
Defaults to 'v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$'
$(GitCommitDateFormat): value passed as the format option when trying to retrieve the git commit date. Defaults to %%cI (windows) or %cI (non windows).
==============================================================
-->
<PropertyGroup>
<!-- Name of remote for repository url -->
<GitRemote Condition="'$(GitRemote)' == ''">origin</GitRemote>
<!-- GitVersionFile allows overriding tags/branch names as a source for base version information -->
<GitVersionFile Condition="'$(GitVersionFile)' == ''">GitInfo.txt</GitVersionFile>
<!-- Default the lookup directory to the project directory unless overriden -->
<GitInfoBaseDir Condition="'$(GitInfoBaseDir)' == ''">$(MSBuildProjectDirectory)</GitInfoBaseDir>
<!-- Look it upwards and grab the first one we find -->
<GitVersionFile Condition="'$([MSBuild]::GetDirectoryNameOfFileAbove($(GitInfoBaseDir), $(GitVersionFile)))' != ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(GitInfoBaseDir), $(GitVersionFile)))\$(GitVersionFile)</GitVersionFile>
<GitDefaultBranch Condition="'$(GitDefaultBranch)' == ''">main</GitDefaultBranch>
<GitDefaultCommit Condition="'$(GitDefaultCommit)' == ''">0000000</GitDefaultCommit>
<GitDefaultVersion Condition="'$(GitDefaultVersion)' == ''">0.0.0</GitDefaultVersion>
<GitInfoReportImportance Condition="'$(GitInfoReportImportance)' == ''">low</GitInfoReportImportance>
<!-- Defaults if overrides are specified when building -->
<GitCommits Condition="'$(GitCommits)' == ''">0</GitCommits>
<GitSkipCache Condition="'$(GitSkipCache)' == ''">false</GitSkipCache>
<SkipReadGitCache Condition="'$(SkipReadGitCache)' == ''">$(GitSkipCache)</SkipReadGitCache>
<SkipWriteGitCache Condition="'$(SkipWriteGitCache)' == ''">$(GitSkipCache)</SkipWriteGitCache>
<GitCachePath Condition="'$(GitCachePath)' == ''">$(IntermediateOutputPath)</GitCachePath>
<GitCommitsIgnoreMerges Condition="'$(GitCommitsIgnoreMerges)' == ''">false</GitCommitsIgnoreMerges>
<!-- If head is detached, use a matching ref under refs/heads, or fall back to using commit hash. -->
<GitNameRevOptions Condition="'$(GitNameRevOptions)' == ''">--refs=refs/heads/* --no-undefined --always</GitNameRevOptions>
<GitTagRegex Condition="'$(GitTagRegex)' == ''">*</GitTagRegex>
<!-- For backwards compatibility if anyone has changed the expression before -->
<GitBaseVersionRegex Condition="'$(_GitBaseVersionExpr)' != ''">$(_GitBaseVersionExpr)</GitBaseVersionRegex>
<GitBaseVersionRegex Condition="'$(GitBaseVersionRegex)' == ''">v?(?<MAJOR>\d+)\.(?<MINOR>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$</GitBaseVersionRegex>
<GitMinVersion>2.5.0</GitMinVersion>
<!-- Under Unix, we don't double %% the format. That only works on Windows. -->
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' == 'Windows_NT'">%%cI</GitCommitDateFormat>
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' != 'Windows_NT'">%cI</GitCommitDateFormat>
<_VsWherePath>$(ProgramFiles(x86))\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
</PropertyGroup>
<!-- Private properties -->
<PropertyGroup>
<CoreCompileDependsOn>GitVersion;GitInfoReport;$(CoreCompileDependsOn)</CoreCompileDependsOn>
<!-- Cache file used to avoid running all git commands. Only GitRoot will be retrieved to determine the path of this cache file. -->
<_GitInfoFile>$(GitCachePath)GitInfo.cache</_GitInfoFile>
<!-- Stores value of GitIsDirty variable from last execution. File is changed when the value changes between runs. -->
<_GitIsDirtyFile>$(GitCachePath)GitIsDirty.cache</_GitIsDirtyFile>
</PropertyGroup>
<PropertyGroup Label="CI" Condition="'$(CI)' == ''">
<CI>false</CI>
<!-- GH, CircleCI, GitLab and BitBucket already use CI -->
<CI Condition="'$(TF_BUILD)' == 'true' or
'$(TEAMCITY_VERSION)' != '' or
'$(APPVEYOR)' != '' or
'$(BuildRunner)' == 'MyGet' or
'$(JENKINS_URL)' != '' or
'$(TRAVIS)' == 'true' or
'$(BUDDY)' == 'true'">true</CI>
</PropertyGroup>
<Import Project="GitInfo.CI.targets" Condition="$(CI) and $(GitBranchCI) != 'false'" />
<Target Name="GitInfoReport" DependsOnTargets="GitVersion">
<Message Importance="$(GitInfoReportImportance)" Text="Git Info:
GitInfoBaseDir: $(GitInfoBaseDir)
GitRoot: $(GitRoot)
GitRepositoryUrl $(GitRepositoryUrl)
GitBranch: $(GitBranch)
GitCommit: $(GitCommit)
GitSha: $(GitSha)
GitCommitDate: $(GitCommitDate)
GitBaseVersion: $(GitBaseVersion)
GitBaseVersionSource: $(GitBaseVersionSource)
GitBaseVersionMajor: $(GitBaseVersionMajor)
GitBaseVersionMinor: $(GitBaseVersionMinor)
GitBaseVersionPatch: $(GitBaseVersionPatch)
GitCommits: $(GitCommits)
GitTag: $(GitTag)
GitBaseTag: $(GitBaseTag)
GitSemVerMajor: $(GitSemVerMajor)
GitSemVerMinor: $(GitSemVerMinor)
GitSemVerPatch: $(GitSemVerPatch)
GitSemVerLabel: $(GitSemVerLabel)
GitSemVerDashLabel: $(GitSemVerDashLabel)
GitSemVerSource: $(GitSemVerSource)
" />
</Target>
<PropertyGroup>
<GitInfoDependsOn>
SetGitExe;
_EnsureGit;
_GitRoot;
_GitInputs;
_GitClearCache;
_GitReadCache;
_GitRepositoryUrl;
_GitBranch;
_GitCommit;
_GitCommitDate;
_GitPopulateInfo;
</GitInfoDependsOn>
</PropertyGroup>
<!-- Under Unix, we don't double %% the format. That only works on Windows. -->
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<_ShortShaFormat>%%h</_ShortShaFormat>
<_LongShaFormat>%%H</_LongShaFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<_ShortShaFormat>%h</_ShortShaFormat>
<_LongShaFormat>%H</_LongShaFormat>
</PropertyGroup>
<Target Name="GitInfo" DependsOnTargets="$(GitInfoDependsOn)" Returns="@(GitInfo)" />
<Target Name="_EnsureGit">
<Exec Command="$(GitExe) --version"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitOutput" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Error Text="Failed to run `git --version`. Git may not be properly installed: %0A $(_GitOutput)" Condition="'$(MSBuildLastExitCode)' != '0'" />
<PropertyGroup>
<_GitCurrentVersion>$([System.Text.RegularExpressions.Regex]::Match("$(_GitOutput)", "\d+\.\d+\.\d+").Value)</_GitCurrentVersion>
</PropertyGroup>
<Warning Text="Could not determine git version from output '$(_GitOutput)'. Required minimum git version is $(GitMinVersion)." Code="GI007" Condition="$(_GitCurrentVersion) == ''" />
<Error Text="Required minimum git version is $(GitMinVersion) but found $(_GitCurrentVersion)." Condition="$(_GitCurrentVersion) != '' and $([System.Version]::Parse('$(_GitCurrentVersion)').CompareTo($([System.Version]::Parse('$(GitMinVersion)')))) < 0" />
</Target>
<Target Name="_GitRoot" Returns="$(GitRoot)" Condition="'$(GitRoot)' == ''">
<Exec Command="$(GitExe) rev-parse --show-toplevel"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitInfoBaseDir)">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitOutput" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' == '0'">
<GitRoot>$([MSBuild]::NormalizeDirectory($(_GitOutput.Trim())))</GitRoot>
</PropertyGroup>
<!-- Account for cygwin/WSL separately -->
<Exec Command='$(CygPathExe) -w "$(_GitOutput)"'
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="false"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitInfoBaseDir)"
Condition="'$(MSBuildLastExitCode)' == '0' and '$(CygPathExe)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitOutput" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' == '0'">
<GitRoot>$([MSBuild]::NormalizeDirectory($(_GitOutput.Trim())))</GitRoot>
</PropertyGroup>
<!-- Determine the .git dir. In the simple case, this is just $(GitRoot)\.git. But in the case of submodules, a .git *file* rather than a directory will be present at that path, with a value like:
gitdir: ../../.git/modules/external/toq
which points to the actual folder where the git info exists in the containing repository. -->
<PropertyGroup>
<GitDir>$([System.IO.Path]::Combine('$(GitRoot)', '.git'))</GitDir>
<_IsGitFile>$([System.IO.File]::Exists('$(GitDir)'))</_IsGitFile>
</PropertyGroup>
<Exec Command="$(GitExe) rev-parse --is-inside-work-tree"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitInfoBaseDir)"
Condition="'$(_IsGitFile)' == 'true'">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitIsWorkTree" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' == '0'">
<_IsGitWorkTree>$(_GitIsWorkTree.Trim())</_IsGitWorkTree>
</PropertyGroup>
<Exec Command="$(GitExe) rev-parse --git-common-dir"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitInfoBaseDir)"
Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' == 'true'">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitCommonDir" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<!-- Account for cygwin/WSL separately -->
<Exec Command='$(CygPathExe) -w "$(_GitCommonDir)"'
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="false"
StandardErrorImportance="high"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitInfoBaseDir)"
Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' == 'true' and '$(MSBuildLastExitCode)' == '0' and '$(CygPathExe)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitCommonDir" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' == 'true'">
<GitDir>$(_GitCommonDir.Trim())</GitDir>
</PropertyGroup>
<PropertyGroup Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' != 'true'">
<_GitFileContents>$([System.IO.File]::ReadAllText('$(GitDir)'))</_GitFileContents>
<GitDir>$(_GitFileContents.Substring(7).Trim())</GitDir>
<GitDir>$([MSBuild]::NormalizeDirectory('$(GitRoot)', '$(GitDir)'))</GitDir>
</PropertyGroup>
<Message Text="Determined Git repository root as '$(GitRoot)'" Importance="$(GitInfoReportImportance)" Condition="'$(GitRoot)' != ''" />
<Message Text="Determined Git dir as '$(GitDir)'" Importance="$(GitInfoReportImportance)" Condition="'$(GitRoot)' != ''" />
<Warning Text="Directory $(GitInfoBaseDir) is not in a Git repository. Cannot determine Git repository root." Code="GI001" Condition="'$(GitRoot)' == ''" />
<Exec Command="$(GitExe) diff --quiet HEAD"
EchoOff="true"
ContinueOnError="true"
IgnoreExitCode="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(GitRoot)' != ''">
<Output TaskParameter="ExitCode" PropertyName="GitIsDirty" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0' or '$(GitIsDirty)' == ''">
<GitIsDirty>0</GitIsDirty>
</PropertyGroup>
<WriteLinesToFile File="$(_GitIsDirtyFile)" Lines="$(GitIsDirty)" Overwrite="true" WriteOnlyWhenDifferent="true" ContinueOnError="true" />
</Target>
<Target Name="_GitInputs" DependsOnTargets="_GitRoot" Returns="@(_GitInput)">
<PropertyGroup>
<_GitHead>$([System.IO.Path]::Combine('$(GitDir)', 'HEAD'))</_GitHead>
<_GitLogsHead>$([System.IO.Path]::Combine('$(GitDir)', 'logs', 'HEAD'))</_GitLogsHead>
<_GitPackedRefs>$([System.IO.Path]::Combine('$(GitDir)', 'packed-refs'))</_GitPackedRefs>
</PropertyGroup>
<ItemGroup>
<_GitInput Include="$(GitVersionFile)" Utdc="true" Condition="Exists('$(GitVersionFile)')" />
<_GitInput Include="$(_GitIsDirtyFile)" Utdc="true" Condition="Exists('$(_GitIsDirtyFile)')" />
<_GitInput Include="$(_GitHead)" Utdc="true" Condition="Exists('$(_GitHead)')" />
<_GitInput Include="$(_GitLogsHead)" Utdc="true" Condition="Exists('$(_GitLogsHead)')" />
<_GitInput Include="$(_GitPackedRefs)" Utdc="true" Condition="Exists('$(_GitPackedRefs)')" />
</ItemGroup>
<CreateItem Include="$([System.IO.Path]::Combine('$(GitDir)', 'refs', 'heads', '**'))">
<Output ItemName="_GitInput" TaskParameter="Include" />
</CreateItem>
<CreateItem Include="$([System.IO.Path]::Combine('$(GitDir)', 'refs', 'tags', '**'))">
<Output ItemName="_GitInput" TaskParameter="Include" />
</CreateItem>
<Delete Files="$(_GitInfoFile)" Condition="Exists('$(_GitInfoFile)') and '$(SkipReadGitCache)' == 'true'" />
</Target>
<!-- If the inputs/outputs are outdated, clear the cache. -->
<Target Name="_GitClearCache" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Condition="Exists('$(_GitInfoFile)')">
<Delete Files="$(_GitInfoFile)" />
</Target>
<Target Name="_GitReadCache" Condition="Exists('$(_GitInfoFile)') and '$(SkipReadGitCache)' != 'true'">
<ReadLinesFromFile File="$(_GitInfoFile)" ContinueOnError="true">
<Output TaskParameter="Lines" ItemName="_GitCachedInfo" />
</ReadLinesFromFile>
<CreateItem Include="GitInfo" AdditionalMetadata="@(_GitCachedInfo -> TrimEnd(';'))">
<Output TaskParameter="Include" ItemName="GitInfo" />
</CreateItem>
<PropertyGroup>
<GitRepositoryUrl Condition="'$(GitRepositoryUrl)' == ''">%(GitInfo.GitRepositoryUrl)</GitRepositoryUrl>
<GitBranch Condition="'$(GitBranch)' == ''">%(GitInfo.GitBranch)</GitBranch>
<GitCommit Condition="'$(GitCommit)' == ''">%(GitInfo.GitCommit)</GitCommit>
<GitSha Condition="'$(GitSha)' == ''">%(GitInfo.GitSha)</GitSha>
<GitCommitDate Condition="'$(GitCommitDate)' == ''">%(GitInfo.GitCommitDate)</GitCommitDate>
<GitBaseVersion Condition="'$(GitBaseVersion)' == ''">%(GitInfo.GitBaseVersion)</GitBaseVersion>
<GitBaseVersionSource Condition="'$(GitBaseVersionSource)' == ''">%(GitInfo.GitBaseVersionSource)</GitBaseVersionSource>
<GitBaseVersionMajor Condition="'$(GitBaseVersionMajor)' == ''">%(GitInfo.GitBaseVersionMajor)</GitBaseVersionMajor>
<GitBaseVersionMinor Condition="'$(GitBaseVersionMinor)' == ''">%(GitInfo.GitBaseVersionMinor)</GitBaseVersionMinor>
<GitBaseVersionPatch Condition="'$(GitBaseVersionPatch)' == ''">%(GitInfo.GitBaseVersionPatch)</GitBaseVersionPatch>
<GitCommits Condition="'$(GitCommits)' == '' or '$(GitCommits)' == '0'">%(GitInfo.GitCommits)</GitCommits>
<GitTag Condition="'$(GitTag)' == ''">%(GitInfo.GitTag)</GitTag>
<GitBaseTag Condition="'$(GitBaseTag)' == ''">%(GitInfo.GitBaseTag)</GitBaseTag>
<GitSemVerMajor Condition="'$(GitSemVerMajor)' == ''">%(GitInfo.GitSemVerMajor)</GitSemVerMajor>
<GitSemVerMinor Condition="'$(GitSemVerMinor)' == ''">%(GitInfo.GitSemVerMinor)</GitSemVerMinor>
<GitSemVerPatch Condition="'$(GitSemVerPatch)' == ''">%(GitInfo.GitSemVerPatch)</GitSemVerPatch>
<GitSemVerLabel Condition="'$(GitSemVerLabel)' == ''">%(GitInfo.GitSemVerLabel)</GitSemVerLabel>
<GitSemVerDashLabel Condition="'$(GitSemVerDashLabel)' == ''">%(GitInfo.GitSemVerDashLabel)</GitSemVerDashLabel>
<GitSemVerSource Condition="'$(GitSemVerSource)' == ''">%(GitInfo.GitSemVerSource)</GitSemVerSource>
</PropertyGroup>
</Target>
<Target Name="_GitRepositoryUrl" DependsOnTargets="_GitRoot" Returns="$(GitRepositoryUrl)" Condition="'$(GitRoot)' != '' and '$(GitRepositoryUrl)' == ''">
<Exec Command="$(GitExe) config --get remote.$(GitRemote).url"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
IgnoreExitCode="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitRepositoryUrl" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Warning Text="Could not retrieve repository url for remote '$(GitRemote)'" Code="GI002" Condition="'$(MSBuildLastExitCode)' != '0'" />
<PropertyGroup>
<!-- Remove username and password from repository URL -->
<GitRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(GitRepositoryUrl), "://[^/]*@", "://"))</GitRepositoryUrl>
</PropertyGroup>
<!--TODO: Sensible default for GitRepositoryUrl-->
</Target>
<Target Name="_GitCommitDate" DependsOnTargets="_GitRoot" Returns="$(GitCommitDate)" Condition="'$(GitRoot)' != '' and '$(GitCommitDate)' == ''">
<Exec Command="$(GitExe) -c log.showSignature=false show --format=$(GitCommitDateFormat) -s"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommitDate" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0'">
<GitCommitDate Condition="$(GitCommitDateFormat.EndsWith('%cI'))">0001-01-01T00:00:00+00:00</GitCommitDate>
<GitCommitDate Condition="!$(GitCommitDateFormat.EndsWith('%cI'))"></GitCommitDate>
</PropertyGroup>
</Target>
<Target Name="_GitBranch" DependsOnTargets="_GitInputs" Returns="$(GitBranch)" Condition="'$(GitBranch)' == ''">
<Exec Command="$(GitExe) rev-parse --abbrev-ref HEAD"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(GitRoot)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="GitBranch" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<!-- CI systems may checkout the specific commit, rather than the branch, so we need to fallback. -->
<Exec Command="$(GitExe) name-rev --name-only $(GitNameRevOptions) HEAD"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(GitRoot)' != '' and '$(GitBranch)' == ''">
<Output TaskParameter="ConsoleOutput" PropertyName="GitBranch" />
</Exec>
<PropertyGroup Condition="'$(GitRoot)' == ''">
<GitBranch>$(GitDefaultBranch)</GitBranch>
</PropertyGroup>
</Target>
<Target Name="_GitCommit" DependsOnTargets="_GitRoot" Returns="$(GitCommit)" Condition="'$(GitRoot)' != '' and '$(GitCommit)' == ''">
<Exec Command="$(GitExe) rev-parse --short HEAD"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommit" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0'">
<GitCommit>$(GitDefaultCommit)</GitCommit>
</PropertyGroup>
<Exec Command="$(GitExe) rev-parse HEAD"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitSha" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0'">
<GitSha>$(GitDefaultCommit)</GitSha>
</PropertyGroup>
</Target>
<Target Name="_GitPopulateInfo">
<ItemGroup>
<GitInfo Include="GitInfo">
<GitRepositoryUrl>$(GitRepositoryUrl)</GitRepositoryUrl>
<GitRoot>$(GitRoot)</GitRoot>
<GitBranch>$(GitBranch)</GitBranch>
<GitCommit>$(GitCommit)</GitCommit>
<GitSha>$(GitSha)</GitSha>
<GitCommitDate>$(GitCommitDate)</GitCommitDate>
</GitInfo>
</ItemGroup>
</Target>
<PropertyGroup>
<GitVersionDependsOn>
GitInfo;
_GitBaseVersionBranch;
_GitBaseVersionTagExists;
_GitBaseVersionTag;
_GitBaseVersionFile;
_GitBaseVersionFallback;
_GitValidateBaseVersion;
_GitPopulateVersionInfo;
_GitWriteCache
</GitVersionDependsOn>
</PropertyGroup>
<Target Name="GitVersion" DependsOnTargets="$(GitVersionDependsOn)" Returns="@(GitInfo)" />
<Target Name="GitSetVersion" DependsOnTargets="GitVersion" Condition="'$(GitVersion)' != 'false'">
<PropertyGroup>
<Version>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$([System.Text.RegularExpressions.Regex]::Replace($(GitBranch), "[^0-9A-Za-z-]", "-")).$(GitCommit)</Version>
<PackageVersion>$(Version)</PackageVersion>
</PropertyGroup>
</Target>
<Target Name="_GitBaseVersionFile" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Returns="$(GitBaseVersion)" Condition="'$(GitBaseVersion)' == '' and Exists('$(GitVersionFile)')">
<PropertyGroup>
<GitBaseVersion>$([System.IO.File]::ReadAllText('$(GitVersionFile)'))</GitBaseVersion>
<GitBaseVersion>$(GitBaseVersion.Trim())</GitBaseVersion>
<IsValidGitBaseVersion>$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(GitBaseVersionRegex)))</IsValidGitBaseVersion>
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion>
</PropertyGroup>
<Error Text="$(GitVersionFile) does not contain a valid base version (found '$(GitBaseVersion)', regex: $(GitBaseVersionRegex))." Condition="'$(IsValidGitBaseVersion)' == 'false'" />
<PropertyGroup>
<_GitVersionFile>$(GitVersionFile)</_GitVersionFile>
<GitBaseVersionSource>$(GitVersionFile)</GitBaseVersionSource>
<GitSemVerSource>File</GitSemVerSource>
</PropertyGroup>
<Message Text="Using base version from version file $(GitVersionFile)'" Importance="normal" />
<!-- Account for cygwin/WSL separately -->
<Exec Command='$(CygPathExe) -u "$(_GitVersionFile)"'
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="false"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(CygPathExe)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitVersionFile" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Exec Command='$(GitExe) -c log.showSignature=false log -n 1 --format=format:$(_ShortShaFormat) "$(_GitVersionFile)"'
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitLastBump" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Warning Text="Could not retrieve last commit for $(GitVersionFile). Defaulting to its declared version '$(GitBaseVersion)' and no additional commits." Code="GI003" Condition="'$(MSBuildLastExitCode)' != '0' or '$(_GitLastBump)' == ''" />
<PropertyGroup>
<GitCommits Condition="'$(MSBuildLastExitCode)' != '0' or '$(_GitLastBump)' == ''">0</GitCommits>
<_GitLastBump>$(_GitLastBump.Trim())</_GitLastBump>
<_DirectoryNameOfVersionFile>$([System.IO.Path]::GetDirectoryName($(GitVersionFile)))</_DirectoryNameOfVersionFile>
<_DirectoryNameOfVersionFile>$([MSBuild]::NormalizeDirectory($(_DirectoryNameOfVersionFile)))</_DirectoryNameOfVersionFile>
<_GitCommitsRelativeTo>$(GitCommitsRelativeTo)</_GitCommitsRelativeTo>
<_GitCommitsRelativeTo Condition="'$(_GitCommitsRelativeTo)' == '' and '$(_DirectoryNameOfVersionFile)' != '$(GitRoot)'">$([System.IO.Path]::GetDirectoryName("$(GitVersionFile)"))</_GitCommitsRelativeTo>
<_GitCommitsRelativeTo Condition="'$(_GitCommitsRelativeTo)' != ''">$([MSBuild]::NormalizeDirectory($(_GitCommitsRelativeTo)))</_GitCommitsRelativeTo>
<!-- Ensure the path is quoted if not empty. Remove trailing directory separator from NormalizeDirectory. -->
<_GitCommitsRelativeTo Condition="'$(_GitCommitsRelativeTo)' != ''">"$(_GitCommitsRelativeTo.Trim('"').TrimEnd('\').TrimEnd('/'))"</_GitCommitsRelativeTo>
<_GitCommitsIgnoreMerges Condition="'$(GitCommitsIgnoreMerges)' == 'true'">--no-merges</_GitCommitsIgnoreMerges>
</PropertyGroup>
<!-- Account for cygwin/WSL separately -->
<Exec Command="$(CygPathExe) -u $(_GitCommitsRelativeTo)"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="false"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(MSBuildLastExitCode)' == '0' and '$(CygPathExe)' != '' and '$(_GitCommitsRelativeTo)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitCommitsRelativeTo" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Exec Command="$(GitExe) rev-list --count --full-history $(_GitCommitsIgnoreMerges) $(_GitLastBump)..HEAD $(_GitCommitsRelativeTo)"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="$(MSBuildLastExitCode) == '0' and '$(_GitLastBump)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommits" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Warning Text="Could not retrieve commits since '$(_GitLastBump)'. Defaulting to zero." Code="GI004" Condition="'$(MSBuildLastExitCode)' != '0'" />
<PropertyGroup>
<GitCommits Condition="'$(MSBuildLastExitCode)' != '0'">0</GitCommits>
</PropertyGroup>
</Target>
<Target Name="_GitBaseVersionBranch" DependsOnTargets="_GitBranch" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Returns="$(GitBaseVersion)" Condition="'$(GitBaseVersion)' == '' and '$(GitIgnoreBranchVersion)' != 'true'">
<PropertyGroup>
<_CandidateValue>$(GitBranch)</_CandidateValue>
<_IndexOfSlash>$(_CandidateValue.LastIndexOf('/'))</_IndexOfSlash>
<_IndexOfSlash Condition="'$(_IndexOfSlash)' == '-1'">$(_CandidateValue.LastIndexOf('\'))</_IndexOfSlash>
<_CandidateValue Condition="'$(_GitBranchIndexOfSlash)' != '-1'">$(_CandidateValue.Substring($([MSBuild]::Add($(_IndexOfSlash), 1))))</_CandidateValue>
<IsValidGitBaseVersion>$([System.Text.RegularExpressions.Regex]::IsMatch($(_CandidateValue), $(GitBaseVersionRegex)))</IsValidGitBaseVersion>
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion>
</PropertyGroup>
<Message Text="Git branch '$(GitBranch)' cannot be used as a version specifier. Skipping branch-based version processing." Importance="low" Condition="'$(IsValidGitBaseVersion)' == 'false'" />
<PropertyGroup Condition="'$(IsValidGitBaseVersion)' == 'true'">
<GitBaseVersion>$(_CandidateValue)</GitBaseVersion>
<GitBaseVersionSource>GitBranch</GitBaseVersionSource>
<GitSemVerSource>Branch</GitSemVerSource>
</PropertyGroup>
<!-- Get the initial commit when the current branch departed from the default branch -->
<Exec Command="$(GitExe) merge-base --fork-point $(GitDefaultBranch)"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(IsValidGitBaseVersion)' == 'true'">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitForkPoint" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Warning Text="Could not retrieve first commit where branch $(GitBranch) forked from $(GitDefaultBranch). Defaulting to zero commits." Code="GI005" Condition="'$(IsValidGitBaseVersion)' == 'true' and '$(MSBuildLastExitCode)' != '0'" />
<PropertyGroup Condition="'$(IsValidGitBaseVersion)' == 'true' and '$(MSBuildLastExitCode)' != '0'">
<GitCommits>0</GitCommits>
</PropertyGroup>
<!-- Get the commit count from the fork point to the current branch head -->
<Exec Command="$(GitExe) rev-list --count $(_GitForkPoint)..HEAD"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(IsValidGitBaseVersion)' == 'true' and '$(MSBuildLastExitCode)' == '0'">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommits" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
</Target>
<Target Name="_GitBaseVersionTagExists" DependsOnTargets="_GitBranch;_GitCommit" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Returns="$(GitBaseTag)" Condition="'$(GitBaseVersion)' == '' and '$(GitIgnoreTagVersion)' != 'true'">
<Exec Command="$(GitExe) describe --tags --match=$(GitTagRegex) --abbrev=0"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
IgnoreExitCode="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitBaseTag" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0'">
<GitCommits>0</GitCommits>
<GitBaseTag></GitBaseTag>
</PropertyGroup>
<Message Text="No git tags exist. Skipping tag processing." Importance="low" Condition="'$(GitBaseTag)' == ''" />
</Target>
<Target Name="_GitBaseVersionTag" DependsOnTargets="_GitBaseVersionTagExists" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Returns="$(GitBaseVersion)" Condition="'$(GitBaseVersion)' == '' and '$(GitIgnoreTagVersion)' != 'true' and '$(GitBaseTag)' != ''">
<!-- At this point we know there is a base tag that we can leverage -->
<Exec Command="$(GitExe) describe --match=$(GitTagRegex) --tags"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)">
<Output TaskParameter="ConsoleOutput" PropertyName="GitTag" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup>
<IsValidGitBaseVersion>$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseTag), $(GitBaseVersionRegex)))</IsValidGitBaseVersion>
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion>
<GitBaseVersion Condition="'$(IsValidGitBaseVersion)' == 'true'">$(GitBaseTag)</GitBaseVersion>
</PropertyGroup>
<Message Text="Current tag '$(GitBaseTag)' cannot be used as a version specifier. Skipping tag-based version processing." Importance="low" Condition="'$(IsValidGitBaseVersion)' == 'false'" />
<PropertyGroup Condition="'$(IsValidGitBaseVersion)' == 'true'">
<GitBaseVersionSource>GitBaseTag</GitBaseVersionSource>
<GitSemVerSource>Tag</GitSemVerSource>
<GitCommits>0</GitCommits>
</PropertyGroup>
<Exec Command="$(GitExe) rev-list $(GitBaseTag) -n 1"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(IsValidGitBaseVersion)' == 'true'">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitBaseTagCommit" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Exec Command="$(GitExe) rev-list --count $(_GitBaseTagCommit)..$(GitCommit)"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(IsValidGitBaseVersion)' == 'true' and '$(_GitBaseTagCommit)' != '' and '$(GitCommit)' != '' and '$(GitCommit)' != '$(GitDefaultCommit)'">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommits" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Warning Text="Failed to retrieve commit count from tag '$(GitBaseTag)' to tip $(GitCommit). Defaulting to zero commits." Code="GI006" Condition="'$(IsValidGitBaseVersion)' == 'true' and '$(MSBuildLastExitCode)' != '0'" />
<PropertyGroup>
<GitCommits Condition="'$(MSBuildLastExitCode)' != '0'">0</GitCommits>
</PropertyGroup>
</Target>
<Target Name="_GitBaseVersionFallback" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Returns="$(GitBaseVersion)" Condition="'$(GitBaseVersion)' == '' and '$(GitDefaultVersion)' != ''">
<PropertyGroup>
<IsValidGitDefaultVersion>$([System.Text.RegularExpressions.Regex]::IsMatch($(GitDefaultVersion), $(GitBaseVersionRegex)))</IsValidGitDefaultVersion>
<IsValidGitDefaultVersion>$(IsValidGitDefaultVersion.Trim())</IsValidGitDefaultVersion>
<GitCommits>0</GitCommits>
</PropertyGroup>
<!-- If $(GitBaseVersion) == '' and $(IsValidGitBaseVersion) == '' -->
<Error Text="Fallback version %24(GitDefaultVersion) value of '$(GitDefaultVersion)' is not a valid SemVer 2.0 string." Condition="'$(IsValidGitDefaultVersion)' == 'false'" />
<Exec Command="$(GitExe) rev-list --count $(GitCommit)"
EchoOff="true"
ConsoleToMSBuild="true"
ContinueOnError="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
WorkingDirectory="$(GitRoot)"
Condition="'$(IsValidGitDefaultVersion)' == 'true' and '$(GitCommit)' != '' and '$(GitCommit)' != '$(GitDefaultCommit)'">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommits" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup>
<GitBaseVersion>$(GitDefaultVersion)</GitBaseVersion>
<GitSemVerSource>Default</GitSemVerSource>
</PropertyGroup>
</Target>
<Target Name="_GitValidateBaseVersion" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)">
<!-- If $(GitBaseVersion) == '', it means we couldn't determine a base version by any probing mechanism. -->
<Error Text="Failed to find a valid base version to use. Please make sure you have a %24(GitVersionFile) file (defaults to '$(GitVersionFile)'), branch, tag or %24(GitDefaultVersion) property with a valid SemVer 2.0 string." Condition="'$(GitBaseVersion)' == ''" />
<PropertyGroup>
<IsValidGitBaseVersion>$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBaseVersion), $(GitBaseVersionRegex)))</IsValidGitBaseVersion>
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion>
</PropertyGroup>
<Error Text="Current %24(GitBaseVersion) value of '$(GitBaseVersion)' is not a valid SemVer 2.0 string." Condition="'$(IsValidGitBaseVersion)' == 'false'" />
</Target>
<Target Name="_GitPopulateVersionInfo">
<PropertyGroup>
<!-- Remove the initial optional 'v' or 'V' from the base version -->
<GitBaseVersion Condition="$(GitBaseVersion.StartsWith('v'))">$(GitBaseVersion.TrimStart('v'))</GitBaseVersion>
<GitBaseVersion Condition="$(GitBaseVersion.StartsWith('V'))">$(GitBaseVersion.TrimStart('V'))</GitBaseVersion>
<GitBaseVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionRegex)).Groups['MAJOR'].Value)</GitBaseVersionMajor>
<GitBaseVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionRegex)).Groups['MINOR'].Value)</GitBaseVersionMinor>
<GitBaseVersionPatch>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionRegex)).Groups['PATCH'].Value)</GitBaseVersionPatch>
<GitBaseVersionPatch Condition="'$(GitBaseVersionPatch)' == ''">0</GitBaseVersionPatch>
<GitSemVerMajor>$(GitBaseVersionMajor)</GitSemVerMajor>
<GitSemVerMinor>$(GitBaseVersionMinor)</GitSemVerMinor>
<GitSemVerPatch>$([MSBuild]::Add('$(GitBaseVersionPatch)', '$(GitCommits)'))</GitSemVerPatch>
<GitSemVerLabel>$([System.Text.RegularExpressions.Regex]::Match($(GitBaseVersion), $(GitBaseVersionRegex)).Groups['LABEL'].Value)</GitSemVerLabel>
<GitSemVerDashLabel Condition="'$(GitSemVerLabel)' != ''">-$(GitSemVerLabel)</GitSemVerDashLabel>
</PropertyGroup>
<ItemGroup>
<_GitInfo Include="@(GitInfo -> Distinct())">
<GitBaseVersion>$(GitBaseVersion)</GitBaseVersion>
<GitBaseVersionSource>$(GitBaseVersionSource)</GitBaseVersionSource>
<GitBaseVersionMajor>$(GitBaseVersionMajor)</GitBaseVersionMajor>
<GitBaseVersionMinor>$(GitBaseVersionMinor)</GitBaseVersionMinor>
<GitBaseVersionPatch>$(GitBaseVersionPatch)</GitBaseVersionPatch>
<GitCommits>$(GitCommits)</GitCommits>
<GitTag>$(GitTag)</GitTag>
<GitBaseTag>$(GitBaseTag)</GitBaseTag>
<GitSemVerMajor>$(GitSemVerMajor)</GitSemVerMajor>
<GitSemVerMinor>$(GitSemVerMinor)</GitSemVerMinor>
<GitSemVerPatch>$(GitSemVerPatch)</GitSemVerPatch>
<GitSemVerLabel>$(GitSemVerLabel)</GitSemVerLabel>
<GitSemVerDashLabel>$(GitSemVerDashLabel)</GitSemVerDashLabel>
<GitSemVerSource>$(GitSemVerSource)</GitSemVerSource>
</_GitInfo>
<GitInfo Remove="@(GitInfo)" />
<GitInfo Include="@(_GitInfo)" />
</ItemGroup>
</Target>
<Target Name="_GitWriteCache" Inputs="@(_GitInput)" Outputs="$(_GitInfoFile)" Condition="'$(SkipWriteGitCache)' != 'true'">
<PropertyGroup>
<_GitInfoContent>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)GitInfo.cache.pp'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitRepositoryUrl$', '$(GitRepositoryUrl)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBranch$', '$(GitBranch)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommits$', '$(GitCommits)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommit$', '$(GitCommit)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommitDate$', '$(GitCommitDate)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSha$', '$(GitSha)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersion$', '$(GitBaseVersion)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersionSource$', '$(GitBaseVersionSource)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersionMajor$', '$(GitBaseVersionMajor)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersionMinor$', '$(GitBaseVersionMinor)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersionPatch$', '$(GitBaseVersionPatch)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitTag$', '$(GitTag)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseTag$', '$(GitBaseTag)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerMajor$', '$(GitSemVerMajor)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerMinor$', '$(GitSemVerMinor)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerPatch$', '$(GitSemVerPatch)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerLabel$', '$(GitSemVerLabel)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerDashLabel$', '$(GitSemVerDashLabel)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSemVerSource$', '$(GitSemVerSource)'))</_GitInfoContent>
</PropertyGroup>
<PropertyGroup>
<_GitInfoFileDir>$([System.IO.Path]::GetDirectoryName('$(_GitInfoFile)'))</_GitInfoFileDir>
</PropertyGroup>
<MakeDir Directories="$(_GitInfoFileDir)" Condition="!Exists('$(_GitInfoFileDir)')" />
<WriteLinesToFile File="$(_GitInfoFile)" Lines="$(_GitInfoContent)" Overwrite="true" />
<ItemGroup>
<FileWrites Include="$(_GitInfoFile)" />
</ItemGroup>
</Target>
<!-- Add git info specific inputs and outputs used for incremental build to fast up-to-date-check group. -->
<!-- See https://github.com/dotnet/project-system/blob/main/docs/up-to-date-check.md for more details. -->
<Target Name="_GitUpToDateCheckInput" DependsOnTargets="_GitInputs" BeforeTargets="CollectUpToDateCheckInputDesignTime">
<ItemGroup>
<UpToDateCheckInput Include="@(_GitInput->WithMetadataValue('Utdc', 'true'))" Set="GitInfo" />
</ItemGroup>
</Target>
<Target Name="_GitUpToDateCheckOutput" BeforeTargets="CollectUpToDateCheckOutputDesignTime">
<ItemGroup>
<UpToDateCheckOutput Include="$(_GitInfoFile)" Set="GitInfo" />
</ItemGroup>
</Target>
<!--
============================================================
GitExe Property
Cascading probing mechanism will try to locate an installed version of git, msysgit, WSL git or cygwin git.
============================================================
-->
<PropertyGroup Condition="'$(GitExe)' == '' and '$(OS)' != 'Windows_NT'">
<GitExe Condition="Exists('/usr/bin/git')">/usr/bin/git</GitExe>
<GitExe Condition="Exists('/usr/local/bin/git')">/usr/local/bin/git</GitExe>
<GitExe Condition="$(GitExe) == ''">git</GitExe>
</PropertyGroup>
<Target Name="SetGitExe" Condition="'$(GitExe)' == '' and '$(OS)' == 'Windows_NT'">
<!-- If git from %PATH% works, just use that. -->
<Exec Command="git --version"
EchoOff="true"
ContinueOnError="true"
IgnoreExitCode="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8">
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(MSBuildLastExitCode)' == '0'">
<GitExe>git</GitExe>
</PropertyGroup>
<PropertyGroup Condition="'$(GitExe)' == ''">
<!-- We probe multiple places, with the first matching one winning. -->
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\Program Files\Git\bin\git.exe')">"C:\Program Files\Git\bin\git.exe"</GitExe>
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\Program Files (x86)\Git\bin\git.exe')">"C:\Program Files (x86)\Git\bin\git.exe"</GitExe>
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\msysgit\bin\git.exe')">C:\msysgit\bin\git.exe</GitExe>
</PropertyGroup>
<!-- Fallback to VS-provided Git -->
<PropertyGroup Condition="'$(GitExe)' == ''">
<_VsWherePath>$(MSBuildProgramFiles32)\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
<_VsWhere Condition="Exists('$(_VsWherePath)')">$(_VsWherePath)</_VsWhere>
<_VsGitPath>\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe</_VsGitPath>
</PropertyGroup>
<!-- This command will return one _VsDir item for each InstallationPath for all installed VS instances -->
<Exec Command='"$(_VsWhere)" -prerelease -property installationPath'
Condition="'$(GitExe)' == '' and '$(_VsWhere)' != ''"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="_VsDir"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(GitExe)' == '' and '$(MSBuildLastExitCode)' == '0'">
<!-- If we got a successful vswhere exec, and still got no GitExe, attempt to locate at each path -->
<GitExe Condition="Exists('%(_VsDir.Identity)$(_VsGitPath)')">"%(_VsDir.Identity)$(_VsGitPath)"</GitExe>
</PropertyGroup>
<!-- If we didn't find it in the PATH nor the above locations, check for git installed in WSL. -->
<Exec Command='"$(MSBuildThisFileDirectory)wslrun.cmd" git --version'
EchoOff="true"
ContinueOnError="true"
IgnoreExitCode="true"
StandardErrorImportance="low"
StandardOutputImportance="low"
StdOutEncoding="utf-8"
Condition="'$(GitExe)' == ''">
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<PropertyGroup Condition="'$(GitExe)' == '' and '$(MSBuildLastExitCode)' == '0'">
<GitExe>"$(MSBuildThisFileDirectory)wslrun.cmd" git</GitExe>
<CygPathExe>"$(MSBuildThisFileDirectory)wslpath.cmd"</CygPathExe>
</PropertyGroup>
<PropertyGroup Condition="'$(GitExe)' == ''">
<!-- Only consider cygwin as a last resort, as it tends to be slower. -->
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\cygwin\bin\git.exe')">C:\cygwin\bin\git.exe</GitExe>
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\cygwin64\bin\git.exe')">C:\cygwin64\bin\git.exe</GitExe>
</PropertyGroup>
<!--
============================================================
CygPathExe Property
If we are using cygwin git, we need to pipe the path to cygpath to convert it into a Windows path. If the path is already a Windows path, it will be returned unchanged.
============================================================
-->
<PropertyGroup>
<CygPathExe Condition="'$(CygPathExe)' == '' and Exists('C:\cygwin\bin\cygpath.exe') and $(GitExe.Contains('cygwin'))">C:\cygwin\bin\cygpath.exe</CygPathExe>
<CygPathExe Condition="'$(CygPathExe)' == '' and Exists('C:\cygwin64\bin\cygpath.exe') and $(GitExe.Contains('cygwin64'))">C:\cygwin64\bin\cygpath.exe</CygPathExe>
</PropertyGroup>
</Target>
<Import Project="GitInfo.AssemblyMetadata.targets" Condition="'$(GitThisAssemblyMetadata)' == 'true'" />
<!-- Legacy generation in place for non-C# or when opted in to templates -->
<Import Project="GitInfo.AssemblyInfo.targets" Condition="'$(Language)' != 'C#' or '$(UseTemplatedCode)' == 'true'" />
<!-- Otherwise, for C# we always use ThisAssembly instead. -->
<Import Project="GitInfo.ThisAssembly.targets" Condition="'$(Language)' == 'C#' and '$(UseTemplatedCode)' != 'true'" />
<PropertyGroup>
<GitInfoImported>true</GitInfoImported>
</PropertyGroup>
</Project>