Skip to content

Commit 7a1f8b1

Browse files
committed
Add vswhere fallback to locate git provided by VS
Fixes #324
1 parent b95a725 commit 7a1f8b1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/GitInfo/build/GitInfo.targets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
<!-- Under Unix, we don't double %% the format. That only works on Windows. -->
9494
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' == 'Windows_NT'">%%cI</GitCommitDateFormat>
9595
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' != 'Windows_NT'">%cI</GitCommitDateFormat>
96+
97+
<_VsWherePath>$(ProgramFiles(x86))\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
9698
</PropertyGroup>
9799

98100
<!-- Private properties -->
@@ -915,6 +917,26 @@
915917
<GitExe Condition="'$(GitExe)' == '' and Exists('C:\msysgit\bin\git.exe')">C:\msysgit\bin\git.exe</GitExe>
916918
</PropertyGroup>
917919

920+
<!-- Fallback to VS-provided Git -->
921+
<PropertyGroup Condition="'$(GitExe)' == ''">
922+
<_VsWherePath>$(MSBuildProgramFiles32)\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
923+
<_VsWhere Condition="Exists('$(_VsWherePath)')">$(_VsWherePath)</_VsWhere>
924+
<_VsGitPath>\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe</_VsGitPath>
925+
</PropertyGroup>
926+
927+
<!-- This command will return one _VsDir item for each InstallationPath for all installed VS instances -->
928+
<Exec Command='"$(_VsWhere)" -prerelease -property installationPath'
929+
Condition="'$(GitExe)' == '' and '$(_VsWhere)' != ''"
930+
ConsoleToMSBuild="true">
931+
<Output TaskParameter="ConsoleOutput" ItemName="_VsDir"/>
932+
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
933+
</Exec>
934+
935+
<PropertyGroup Condition="'$(GitExe)' == '' and '$(MSBuildLastExitCode)' == '0'">
936+
<!-- If we got a successful vswhere exec, and still got no GitExe, attempt to locate at each path -->
937+
<GitExe Condition="Exists('%(_VsDir.Identity)$(_VsGitPath)')">"%(_VsDir.Identity)$(_VsGitPath)"</GitExe>
938+
</PropertyGroup>
939+
918940
<!-- If we didn't find it in the PATH nor the above locations, check for git installed in WSL. -->
919941
<Exec Command='"$(MSBuildThisFileDirectory)wslrun.cmd" git --version'
920942
EchoOff="true"

0 commit comments

Comments
 (0)