Reputation: 119
I have to use a git command to get the commit hash. I found several approachs but it doesn't seem to work. This is much easier if I use a powershell script where I can import git.exe with $env:Path += ";C:\Program Files (x86)\Git\bin"
. The fact is that I don't want to use external scripts (such as powershell ones) or importing anything. Is there a way to do that only with msbuild?
I've tried using:
<Exec Command="git describe --long --always" ConsoleToMSBuild="true" />
error MSB3073: The command "git describe --long --always" exited with code 9009.
and
<Exec Command="$env:Path += ';C:\Program Files (x86)\Git\bin'; git describe --long --always" ConsoleToMSBuild="true" />
error MSB3073: The command "$env:Path += ';C:\Program Files (x86)\Git\bin'" exited with code 123
I don't know why question is on powershell :s
Now I'm using the following line:
<Exec WorkingDirectory="$(MSBuildProjectDirectory)" Command="& 'C:\Program Files (x86)\Git\bin\git.exe' describe --long --always" ConsoleToMSBuild="true" />
which throws the error: error MSB3073: The command "& '(...)' describe --long --always" exited with code 255..
Upvotes: 0
Views: 1221
Reputation: 119
After a lot of tries, I did it:
<Exec Command="powershell.exe & "C:\Program Files (x86)\Git\bin\git.exe" describe --long --always" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" ItemName="Version" />
</Exec>
Upvotes: 0