dommer
dommer

Reputation: 19810

How do I add Git to MSBuild script?

I'm trying to add Git check-in as part of my MSBuild script. I want to:

  1. Commit the files with a message
  2. Push the commit
  3. Tag the build
  4. Push the tag

The build script is in ./Build/ (where . is the solution folder).

I'm using:

<Target Name="Committed" DependsOnTargets="SignedInstaller">
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. commit -m &quot;$(Changes)&quot;"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. push"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. tag -a v$(VersionNumber) -m &quot;$(Changes)&quot;"/>
  <Exec Command="&quot;$(GitInstallationFolderPath)cmd\git.exe&quot; --git-dir=..\.git --work-tree=.. push -- tags"/>
</Target>  

The custom properties are all OK.

The first commit exits with 1 and breaks the build.

I'm not sure if I just need to tweak this, or if I'm going about it all wrong, so advice would be welcome. I need to do some to add any new files to Git too - just haven't got that far yet. I do want to stick with MSBuild, though as we have a lot of scripts now. I just want to remove my SVN targets and move to Git.

Upvotes: 3

Views: 4856

Answers (1)

JDługosz
JDługosz

Reputation: 5642

Unlike the limited features of the GitTasks found in MSBuild Extensions, there seems to be more general purpose stuff in the Community Tasks.

GitBranch   A task to get the name of the branch or tag of git repository
GitClient   A task for Git commands.
GitCommits  A task for git to retrieve the number of commits on a revision.
GitDescribe     A task for git to get the most current tag, commit count since tag, and commit hash.
GitPendingChanges   A task for git to detect if there are pending changes
GitVersion  A task for git to get the current commit hash.

Upvotes: 2

Related Questions