devlooped / GitInfo

Git and SemVer Info from MSBuild, C# and VB
https://clarius.org/GitInfo
MIT License
556 stars 70 forks source link

SetGitExe doesn't recognize VS Git locations #324

Closed chrpai closed 1 week ago

chrpai commented 11 months ago

Describe the Bug

I'm building a project that uses GitInfo. On a clean machine with only VS it fails to detect git. Upon reviewing GitInfo.targets I see:

    <PropertyGroup Condition="'$(GitExe)' == ''">
      <!-- We probe multiple places, with the first matching one winning -->
      <GitExe Condition="'$(GitExe)' == '' And Exists('C:\Program Files\Git\bin\git.exe')">"C:\Program Files\Git\bin\git.exe"</GitExe>
      <GitExe Condition="'$(GitExe)' == '' And Exists('C:\Program Files (x86)\Git\bin\git.exe')">"C:\Program Files (x86)\Git\bin\git.exe"</GitExe>
      <GitExe Condition="'$(GitExe)' == '' And Exists('C:\msysgit\bin\git.exe')">C:\msysgit\bin\git.exe</GitExe>
    </PropertyGroup>

VS 2022 by default installs Git to two locations. Would it be acceptable to update the targets to use these locations if found?

Directory of C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd

11/30/2023 01:48 PM 45,048 git.exe 1 File(s) 45,048 bytes

Directory of C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin

11/30/2023 01:48 PM 3,806,712 git.exe 1 File(s) 3,806,712 bytes

Back this issue Back this issue

kzu commented 9 months ago

Yes, it would be totally ok! Feel free to send a PR and I'll merge and ship it (provided both work just like the others).

Thanks!

gitfool commented 9 months ago

To do this properly you should use vswhere as there are many possible locations for visual studio; e.g. on my machine:

❯ "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -property installationPath
C:\Program Files\Microsoft Visual Studio\2022\Preview

(I only have the preview of 2022 installed so specifying -prerelease is important.)

Also, you should only need ...\Git\cmd\git.exe and not ...\Git\mingw64\bin\git.exe, unless I'm missing something.

kzu commented 9 months ago

Yep, likely just a matter of packaging the tool and invoking it from MSBuild.

kzu commented 5 months ago

you're on a roll @gitfool, perhaps you can tackle this one too! 🙏