kevicency / MSBuild.NodeTools

Run various node tools as a MSBuild dependency
BSD 3-Clause "New" or "Revised" License
64 stars 14 forks source link

Issue when defining LocalGitPath #31

Open dcbroad3 opened 8 years ago

dcbroad3 commented 8 years ago

When we define the LocalGitPath, the GitPath is set in MSBuild.Bower.targets.

    <PropertyGroup Condition=" '$(LocalGitPath)' != '' ">
        <GitPath>$(LocalGitPath)</GitPath>
        <EnsureGitInPathCmd>SETLOCAL &amp; SET PATH=$(LocalGitPath);%PATH% &amp;</EnsureGitInPathCmd>
    </PropertyGroup>

Then, GitPath is not empty, so we skip the Exec that follows:

    <Exec Command="$(WINDIR)\system32\where.exe git"
        ContinueOnError="true"
        IgnoreExitCode="true"
        ConsoleToMsBuild="true"
        Condition=" '$(GitPath)' == '' ">
        <Output TaskParameter="ExitCode" PropertyName="WhereExitCode"/>
        <Output TaskParameter="ConsoleOutput" PropertyName="GitExecutable" />
    </Exec>

However, when we get to the PropertyGroup that follows the Exec, the Condition is met because $(WhereExitCode) is 0 (from a previous target, presumably), but $(GitExecutable) is empty, so an error is thrown when GetDirectoryName is called:

    <PropertyGroup Condition=" '$(WhereExitCode)' == '0' ">
        <GitPath>$([System.IO.Path]::GetDirectoryName('$(GitExecutable)'))</GitPath>
    </PropertyGroup>

I propose adding another condition; the below seems to work for me:

    <PropertyGroup Condition=" '$(GitPath)' == '' AND '$(WhereExitCode)' == '0' ">
        <GitPath>$([System.IO.Path]::GetDirectoryName('$(GitExecutable)'))</GitPath>
    </PropertyGroup>

Of course, WhereExitCode could also be renamed to something unique.