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
EDIT
I don't know why question is on powershell :s
UPDATE
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..
Command="C:\Program Files (x86)\Git\bin\git describe --long --always"?git describecommand should always succeed and return something on stdout. Hence the problem is probably elsewhere. I would try and run it separately, but as close to what you have in your csproj as possible. I would also ask myself one very important question: Do I really need to do this? From what you've shown, the output isn't used - so is there any point in putting in the time and effort to get it to work?