Skip to content

Commit

Permalink
Add vswhere fallback to locate git provided by VS
Browse files Browse the repository at this point in the history
Fixes #324
  • Loading branch information
kzu committed Nov 2, 2024
1 parent b95a725 commit 7a1f8b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
<!-- Under Unix, we don't double %% the format. That only works on Windows. -->
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' == 'Windows_NT'">%%cI</GitCommitDateFormat>
<GitCommitDateFormat Condition="'$(GitCommitDateFormat)' == '' and '$(OS)' != 'Windows_NT'">%cI</GitCommitDateFormat>

<_VsWherePath>$(ProgramFiles(x86))\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
</PropertyGroup>

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

<!-- Fallback to VS-provided Git -->
<PropertyGroup Condition="'$(GitExe)' == ''">
<_VsWherePath>$(MSBuildProgramFiles32)\Microsoft Visual Studio\Installer\vswhere.exe</_VsWherePath>
<_VsWhere Condition="Exists('$(_VsWherePath)')">$(_VsWherePath)</_VsWhere>
<_VsGitPath>\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe</_VsGitPath>
</PropertyGroup>

<!-- This command will return one _VsDir item for each InstallationPath for all installed VS instances -->
<Exec Command='"$(_VsWhere)" -prerelease -property installationPath'
Condition="'$(GitExe)' == '' and '$(_VsWhere)' != ''"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="_VsDir"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<PropertyGroup Condition="'$(GitExe)' == '' and '$(MSBuildLastExitCode)' == '0'">
<!-- If we got a successful vswhere exec, and still got no GitExe, attempt to locate at each path -->
<GitExe Condition="Exists('%(_VsDir.Identity)$(_VsGitPath)')">"%(_VsDir.Identity)$(_VsGitPath)"</GitExe>
</PropertyGroup>

<!-- If we didn't find it in the PATH nor the above locations, check for git installed in WSL. -->
<Exec Command='"$(MSBuildThisFileDirectory)wslrun.cmd" git --version'
EchoOff="true"
Expand Down

0 comments on commit 7a1f8b1

Please sign in to comment.