-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directory.Build.props
47 lines (47 loc) · 3.83 KB
/
Directory.Build.props
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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="LogBuild;GetGitRevision">
<PropertyGroup>
<ThisProjectBuildLogFileName Condition="'$(MSBuildProjectName)' == ''">$(MSBuildThisFileDirectory)BuildCommandLines.log</ThisProjectBuildLogFileName>
<ThisProjectBuildLogFileName Condition="'$(MSBuildProjectName)' != ''">$(MSBuildThisFileDirectory)BuildCommandLines-$(MSBuildProjectName).log</ThisProjectBuildLogFileName>
<PreferredToolArchitecture Condition="'$(PreferredToolArchitecture)' == '' and ('$(PROCESSOR_ARCHITECTURE)' == 'AMD64')">x64</PreferredToolArchitecture>
<GitWorkTreeRootDir>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), '.git\refs\heads\main'))</GitWorkTreeRootDir>
<GitWorkTreeRootDir Condition="'$(GitWorkTreeRootDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), '.git\refs\heads\master'))</GitWorkTreeRootDir>
<GitWorkTreeRootDir Condition="'$(GitWorkTreeRootDir)' != '' and !HasTrailingSlash('$(GitWorkTreeRootDir)')">$(GitWorkTreeRootDir)\</GitWorkTreeRootDir>
<GitDirSentinelFile Condition="Exists('$(GitWorkTreeRootDir).git\HEAD')">$(GitWorkTreeRootDir).git\HEAD</GitDirSentinelFile>
</PropertyGroup>
<Target Name="LogBuild" BeforeTargets="SetUserMacroEnvironmentVariables;SetBuildDefaultEnvironmentVariables">
<Message Text="Setting LOG_BUILD_COMMANDLINES='$(ThisProjectBuildLogFileName)'" />
<SetEnv Name="LOG_BUILD_COMMANDLINES" Value="$(ThisProjectBuildLogFileName)" Prefix="false" />
<SetEnv Name="PreferredToolArchitecture" Value="$(PreferredToolArchitecture)" Prefix="false" />
<Message Importance="high" Text="Retrieved %24(GitWorkTreeRootDir) = '$(GitWorkTreeRootDir)'" Condition="'$(GitWorkTreeRootDir)' != ''" />
</Target>
<Target Name="FindGitExecutablePath" Condition="'$(GitDirSentinelFile)' != ''">
<PropertyGroup>
<_GitExecutableToFind>git.exe</_GitExecutableToFind>
</PropertyGroup>
<ItemGroup>
<_GitExecPaths Include="$([System.Environment]::GetEnvironmentVariable('PATH').Split(';'))" />
<_GitFilteredExecPaths Include="@(_GitExecPaths)" Condition="Exists('%(FullPath)\$(_GitExecutableToFind)')" />
<_GitFilteredExecPaths Include="@(_GitFilteredExecPaths->Reverse())" Condition="Exists('%(FullPath)\$(_GitExecutableToFind)')" />
</ItemGroup>
<PropertyGroup>
<GitExecutableFullPath Condition="'%(_GitFilteredExecPaths.Identity)' != ''">%(_GitFilteredExecPaths.Identity)\$(_GitExecutableToFind)</GitExecutableFullPath>
<GitExecutableFullPath Condition="'%(_GitFilteredExecPaths.Identity)' == ''"></GitExecutableFullPath>
</PropertyGroup>
</Target>
<Target Name="GetGitRevision" DependsOnTargets="FindGitExecutablePath" Condition="'$(GitDirSentinelFile)' != ''">
<Message Importance="high" Text="Detecting Git revision, since '$(GitDirSentinelFile)' was found. Using %24(GitExecutableFullPath) = '$(GitExecutableFullPath)'." Condition="'$(GitExecutableFullPath)' != '' and '$(GitWorkTreeRootDir)' != ''" />
<Exec Command=""$(GitExecutableFullPath)" -C "$(GitWorkTreeRootDir)\" rev-parse HEAD" EchoOff="true" Condition="'$(GitExecutableFullPath)' != '' and '$(GitWorkTreeRootDir)' != ''" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitRevision" />
</Exec>
<Message Importance="high" Text="Retrieved for HEAD %24(GitRevision) = '$(GitRevision)'." Condition="'$(GitRevision)' != ''" />
<ItemGroup Condition="'$(GitRevision)' != ''">
<ClCompile>
<PreprocessorDefinitions>GIT_COMMIT="$(GitRevision)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>GIT_COMMIT="$(GitRevision)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemGroup>
</Target>
</Project>