-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitVersion.targets
67 lines (61 loc) · 3.4 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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Copyright (C) 2023 Jefferson Montgomery
SPDX-License-Identifier: MIT -->
<!-- GVT options; set these properties before importing GitVersion.targets to override
GVT_ReadBranch Whether or not to read/set the GVT_BRANCH define
GVT_ReadCommit Whether or not to read/set the GVT_COMMIT define
GVT_CommitHashLength How many characters of the hash to use in GVT_COMMIT (0==all)
GVT_DirtySuffix What suffix to use on the hash if the repository has modified files -->
<PropertyGroup>
<GVT_ReadBranch Condition="'$(GVT_ReadBranch)'==''">true</GVT_ReadBranch>
<GVT_ReadCommit Condition="'$(GVT_ReadCommit)'==''">true</GVT_ReadCommit>
<GVT_CommitHashLength Condition="'$(GVT_CommitHashLength)'==''">0</GVT_CommitHashLength>
<GVT_CommitDirtySuffix Condition="'$(GVT_CommitDirtySuffix)'==''">-dirty</GVT_CommitDirtySuffix>
</PropertyGroup>
<!-- This is required so that Visual Studio knows about the defines and that they are strings.
It's a bit annoying becasue I don't know how to replace them, so the compile command line will
have duplicate defines (these empty ones, and then the correct ones later). -->
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition="'$(GVT_ReadBranch)'=='true'">%(PreprocessorDefinitions);GVT_BRANCH="";</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(GVT_ReadCommit)'=='true'">%(PreprocessorDefinitions);GVT_COMMIT="";</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<!-- This target reads the version and stores them as properties. -->
<Target Name="GVT_ReadVersion" BeforeTargets="PrepareForBuild">
<Exec Condition="'$(GVT_ReadBranch)'=='true'"
Command="git.exe rev-parse --abbrev-ref HEAD"
ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GVT_Branch" />
</Exec>
<Exec Condition="'$(GVT_ReadCommit)'=='true'"
Command="git.exe describe --always --abbrev=$(GVT_CommitHashLength) --dirty="$(GVT_CommitDirtySuffix)" --match=" ""
ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GVT_Commit" />
</Exec>
<ItemGroup Condition="'$(MSBuildProjectExtension)'=='.csproj'">
<GVT_CSFileLine Include="public static class GVT {" />
<GVT_CSFileLine Include=" public static readonly string COMMIT="$(GVT_Commit)"%3B" />
<GVT_CSFileLine Include=" public static readonly string BRANCH="$(GVT_Branch)"%3B" />
<GVT_CSFileLine Include="}" />
</ItemGroup>
<WriteLinesToFile Condition="'$(MSBuildProjectExtension)'=='.csproj'"
File="$(MSBUILDProjectDirectory)\GVT_GitVersion.cs"
Lines="@(GVT_CSFileLine)"
Overwrite="true" />
</Target>
<!-- This target adds the defines to any compiled files. -->
<Target Name="GVT_AddVersion" BeforeTargets="ClCompile">
<ItemGroup>
<ClCompile>
<PreprocessorDefinitions>
%(PreprocessorDefinitions);
GVT_BRANCH="$(GVT_Branch)";
GVT_COMMIT="$(GVT_Commit)";
</PreprocessorDefinitions>
</ClCompile>
</ItemGroup>
</Target>
</Project>