This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir.targets
101 lines (89 loc) · 5.82 KB
/
dir.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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" InitialTargets="CheckForBuildTools" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CheckForBuildTools">
<Error Condition="!Exists('$(ToolsDir)')"
Text="The tools directory [$(ToolsDir)] does not exist. Please run sync in your enlistment to ensure the tools are installed before attempting to build an individual project." />
</Target>
<!-- Provide default targets which can be hooked onto or overridden as necessary -->
<Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
<Target Name="RebuildAndTest" DependsOnTargets="Rebuild;Test" />
<Target Name="Test" />
<Import Project="$(ToolsDir)/Build.Common.targets" Condition="Exists('$(ToolsDir)Build.Common.targets') and '$(UseLiveBuildTools)' != 'true'" />
<Target Name="GetLatestCommitHash">
<!-- Get the latest commit hash -->
<Exec Command="git rev-parse HEAD 2>&1" StandardOutputImportance="Low" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
<Output TaskParameter="ExitCode" PropertyName="LatestCommitExitCode" />
</Exec>
<!-- We shouldn't fail the build if we can't retreive the commit hash, so in this case just set it to N/A -->
<PropertyGroup Condition="'$(LatestCommitExitCode)'!='0'">
<LatestCommit>N/A</LatestCommit>
</PropertyGroup>
</Target>
<Target Name="GetCommitCount">
<Exec Command="git rev-list --count HEAD"
StandardOutputImportance="Low"
IgnoreExitCode="true"
IgnoreStandardErrorWarningFormat="true"
ConsoleToMSBuild="true"
Condition="'$(CommitCount)' == ''">
<Output TaskParameter="ConsoleOutput" PropertyName="CommitCount" />
<Output TaskParameter="ExitCode" PropertyName="CommitCountExitCode" />
</Exec>
<Error Condition="'$(CommitCount)' == ''" Text="Unable to determine the 'commit count'. 'Commit count' is used for generating an msi version. If you are building outside of a git repo, you must pass the '/p:CommitCount=[value]' property" />
</Target>
<Target Name="GetBundleDisplayVersion">
<PropertyGroup>
<BundleDisplayVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion).$(BuildNumberMajor)</BundleDisplayVersion>
</PropertyGroup>
</Target>
<!-- Override Target from buildtools -->
<Target Name="GenerateVersionHeader"
Inputs="$(MSBuildProjectFile)"
Outputs="$(NativeVersionHeaderFile)"
DependsOnTargets="CreateVersionFileDuringBuild;GetLatestCommitHash"
Condition="'$(NativeVersionHeaderFile)'!='' and '$(GenerateVersionHeader)'=='true' and !Exists($(NativeVersionHeaderFile))">
<ItemGroup>
<!-- Defining versioning variables -->
<NativeVersionLines Include="#include <Windows.h>" />
<NativeVersionLines Include="#ifndef VER_COMPANYNAME_STR" />
<NativeVersionLines Include="#define VER_COMPANYNAME_STR "Microsoft Corporation"" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#ifndef VER_FILEDESCRIPTION_STR" />
<NativeVersionLines Include="#define VER_FILEDESCRIPTION_STR "$(AssemblyName)"" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#ifndef VER_INTERNALNAME_STR" />
<NativeVersionLines Include="#define VER_INTERNALNAME_STR VER_FILEDESCRIPTION_STR" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#ifndef VER_ORIGINALFILENAME_STR" />
<NativeVersionLines Include="#define VER_ORIGINALFILENAME_STR VER_FILEDESCRIPTION_STR" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#ifndef VER_PRODUCTNAME_STR" />
<NativeVersionLines Include="#define VER_PRODUCTNAME_STR "Microsoft\xae .NET Core Framework"" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#undef VER_PRODUCTVERSION" />
<NativeVersionLines Include="#define VER_PRODUCTVERSION $(MajorVersion),$(MinorVersion),$(BuildNumberMajor),$(BuildNumberMinor)" />
<NativeVersionLines Include="#undef VER_PRODUCTVERSION_STR" />
<NativeVersionLines Include="#define VER_PRODUCTVERSION_STR "$(MajorVersion).$(MinorVersion).$(BuildNumberMajor).$(BuildNumberMinor)$(BuiltByString). Commit Hash%3A $(LatestCommit)"" />
<NativeVersionLines Include="#undef VER_FILEVERSION" />
<NativeVersionLines Include="#define VER_FILEVERSION $(MajorVersion),$(MinorVersion),$(BuildNumberMajor),$(BuildNumberMinor)" />
<NativeVersionLines Include="#undef VER_FILEVERSION_STR" />
<NativeVersionLines Include="#define VER_FILEVERSION_STR "$(MajorVersion).$(MinorVersion).$(BuildNumberMajor).$(BuildNumberMinor)$(BuiltByString). Commit Hash%3A $(LatestCommit)"" />
<NativeVersionLines Include="#ifndef VER_LEGALCOPYRIGHT_STR" />
<NativeVersionLines Include="#define VER_LEGALCOPYRIGHT_STR "\xa9 Microsoft Corporation. All rights reserved."" />
<NativeVersionLines Include="#endif" />
<NativeVersionLines Include="#ifndef VER_DEBUG" />
<NativeVersionLines Condition="'$(Configuration)'=='Debug'" Include="#define VER_DEBUG VS_FF_DEBUG" />
<NativeVersionLines Condition="'$(Configuration)'!='Debug'" Include="#define VER_DEBUG 0" />
<NativeVersionLines Include="#endif" />
</ItemGroup>
<MakeDir Condition="!Exists('$(NativeVersionFileDir)')" Directories="$(NativeVersionFileDir)" />
<WriteLinesToFile
File="$(NativeVersionHeaderFile)"
Lines="@(NativeVersionLines)"
Overwrite="true" />
<ItemGroup>
<FileWrites Include="$(NativeVersionHeaderFile)" />
</ItemGroup>
</Target>
</Project>