-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directory.Build.targets
145 lines (126 loc) · 6.72 KB
/
Directory.Build.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
<Project>
<!-- Generate escalate.globalconfig via dotnet build -property:Escalate=true -->
<Import
Condition="'$(Escalate)' == 'true' and '$(MSBuildProjectExtension)' == '.csproj'"
Project="C:\Users\mw\Projects\Learning\netanalyzers-usagelab\EscalateHiddenDiagnostics\EscalateHiddenDiagnostics.targets"
/>
<!--
============================================================
EnableGitCommitCount - Defaults to 'true' for regular builds
EnableGitCommitCountForwarder - Defaults to $(EnableGitCommitCount)
GitCommitCount - Sets $(GitCommitCount). Requires 'git' to be in PATH.
============================================================
-->
<PropertyGroup>
<EnableGitCommitCount
Condition="'$(EnableGitCommitCount)' == '' and
'$(DesignTimeBuild)' != 'true' and
'$(BuildingForLiveUnitTesting)' != 'true'">true</EnableGitCommitCount>
<EnableGitCommitCountForwarder
Condition="'$(EnableGitCommitCountForwarder)' == '' or
'$(EnableGitCommitCount)' != 'true'">$(EnableGitCommitCount)</EnableGitCommitCountForwarder>
</PropertyGroup>
<Target Name="GitCommitCount"
Condition="'$(GitCommitCount)' == '' and '$(EnableGitCommitCount)' == 'true'">
<Exec Command="git rev-list --count HEAD"
ConsoleToMSBuild="true"
IgnoreExitCode="false"
StandardErrorImportance="high"
StandardOutputImportance="low">
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
<Output Condition="'$(MSBuildLastExitCode)' == '0'"
TaskParameter="ConsoleOutput" PropertyName="GitCommitCount" />
</Exec>
</Target>
<!--
============================================================
GitCommitCountForInnerBuild
GitCommitCountForRestoreGraph
GitCommitCountForProjectReference
Minimize git command execution by passing GitCommitCount to inner builds.
For repos with a large history, consider setting GitCommitCount as an environment variable
before building the project(s), e.g. in Powershell: $env:GitCommitCount = git rev-list −−count HEAD
============================================================
-->
<Target Name="GitCommitCountForInnerBuild"
AfterTargets="_ComputeTargetFrameworkItems"
BeforeTargets="DispatchToInnerBuilds"
DependsOnTargets="GitCommitCount"
Condition="'$(EnableGitCommitCountForwarder)' == 'true'">
<ItemGroup Condition="'$(GitCommitCount)' != ''">
<_InnerBuildProjects
Update="*"
AdditionalProperties="%(_InnerBuildProjects.AdditionalProperties);GitCommitCount=$(GitCommitCount)" />
</ItemGroup>
</Target>
<Target Name="GitCommitCountForRestoreGraph"
AfterTargets="_LoadRestoreGraphEntryPoints"
BeforeTargets="_FilterRestoreGraphProjectInputItems"
DependsOnTargets="GitCommitCount"
Condition="'$(EnableGitCommitCountForwarder)' == 'true'">
<ItemGroup Condition="'$(GitCommitCount)' != ''">
<RestoreGraphProjectInputItems
Update="*"
AdditionalProperties="%(RestoreGraphProjectInputItems.AdditionalProperties);GitCommitCount=$(GitCommitCount)" />
</ItemGroup>
</Target>
<Target Name="GitCommitCountForProjectReference"
AfterTargets="AssignProjectConfiguration"
BeforeTargets="_SplitProjectReferencesByFileExistence"
DependsOnTargets="GitCommitCount"
Condition="'$(EnableGitCommitCountForwarder)' == 'true' and '$(BuildProjectReferences)' == 'true'">
<ItemGroup Condition="'$(GitCommitCount)' != ''">
<ProjectReferenceWithConfiguration
Update="*"
AdditionalProperties="%(ProjectReferenceWithConfiguration.AdditionalProperties);GitCommitCount=$(GitCommitCount)" />
</ItemGroup>
</Target>
<!--
============================================================
UpdateVersion
Updates $(Version), $(PackageVersion), and $(FileVersion) with $(GitCommitCount)
for all major build targets (Restore, Build, Pack).
$(Version) - If it contains any -/+ label, $(GitCommitCount) is appended.
If it is only Major.Minor.Patch, it will remain unchanged
and adding the SourceRevisionID to $(InformationalVersion)
will be supressed.
$(PackageVersion) - If undefined or equal $(Version), set to updated $(Version).
$(FileVersion) - If undefined, set to Major.Minor.Patch of $(Version).
If less than four parts, $(GitCommitCount) is ALWAYS appended.
============================================================
-->
<Target Name="UpdateVersion"
BeforeTargets="
_GenerateRestoreProjectSpec;
GetAssemblyVersion;
_GetOutputItemsFromPack;
_GetProjectVersion;
GenerateNuspec"
DependsOnTargets="GitCommitCount">
<PropertyGroup Condition="'$(GitCommitCount)' != ''">
<_SetPackageVersion>false</_SetPackageVersion>
<_SetPackageVersion
Condition="'$(PackageVersion)' == '' or
'$(PackageVersion)' == '$(Version)'">true</_SetPackageVersion>
<_FirstPlus>$(Version.IndexOf("+"))</_FirstPlus>
<_FirstPlus Condition="$(_FirstPlus) < 0">$(Version.Length)</_FirstPlus>
<_FirstHyphen>$(Version.IndexOf("-"))</_FirstHyphen>
<_FirstHyphen Condition="$(_FirstHyphen) < 0">$(Version.Length)</_FirstHyphen>
<_VersionPrefix>$(Version.Substring(0,
$([System.Math]::Min($(_FirstHyphen), $(_FirstPlus)))))</_VersionPrefix>
<!-- GitCommitCount is added to Version with pre-release and/or build labels .
Otherwise it is considered an official release (and SourceRevisionId will be supressed as well). -->
<Version Condition="'$(_VersionPrefix)' != '$(Version)'">$(Version).$(GitCommitCount)</Version>
<!-- PackageVersion has been set during eval and needs to be updated. -->
<PackageVersion Condition="$(_SetPackageVersion)">$(Version)</PackageVersion>
<FileVersion Condition="'$(FileVersion)' == ''">$(_VersionPrefix)</FileVersion>
<!-- GitCommitCount is always added to FileVersion if it has less than 4 parts. -->
<FileVersion
Condition="$(FileVersion.Split('.').Length) < 4">$(FileVersion).$(GitCommitCount)</FileVersion>
<!-- InformationalVersion will be set in Target GetAssemblyVersion and
SourceRevisionID will be added in Target AddSourceRevisionToInformationalVersion afterwards. -->
<IncludeSourceRevisionInInformationalVersion
Condition="'$(_VersionPrefix)' == '$(Version)'">false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>
</Target>
</Project>