Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vswhere fallback to locate git provided by VS #372

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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