Nicolás Villar
Nicolás Villar

Reputation: 119

How to execute git commands in csproj script?

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="&amp; '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

Answers (1)

Nicol&#225;s Villar
Nicol&#225;s Villar

Reputation: 119

After a lot of tries, I did it:

<Exec Command="powershell.exe &amp; &quot;C:\Program Files (x86)\Git\bin\git.exe&quot; describe --long --always" ConsoleToMSBuild="true">
    <Output TaskParameter="ConsoleOutput" ItemName="Version" />
</Exec>

Upvotes: 0

Related Questions