Custom MSBuild tasks to clone Git repositories and more…

Every good work of software starts by scratching a developer's personal itch.
Eric Raymond – The Cathedral and the Bazaar
I love Git. I like the way it completely changed my way of thinking about version control. It has completely replaced Subversion for my personal projects.
I also love MSBuild. It is in my opinion an underappreciated, flexible, extensible and relatively unknown technology that can handle all your build problems. It is my first choice as a build tool for all continuous integration projects.
MSBuild is effectively an untyped Lisp-2 with ugly XML syntax
snprbob86 on Reddit

MSBuild does have community tasks that integrate with different version control systems, but Git is not one of them. (The Git love is spreading slowly in the Windows community…)
What else to do but write my own custom MSBuild tasks that integrate with Git? So, I present MSBuildGitTasks

A typical use case for  MSBuildGitTasks in my MSBuild projects:
  • Clone a Git repository onto the build computer.
  • Switch to a specific branch in the newly cloned local repository.
  • Retrieve the SHA from the latest commit in that branch (to be used as version information for the build).
  • Start compiling…
MSBuildGitTasks is released as open source (with a GPL3 license) and can be found on my Github page. Pull requests/patches are welcomed. There’s also an issue tracker if you want to report anything.
I consider this a 0.1 release. It works for my workflow and my combination of hardware/software. That said, the software is extremely simple and should be easy to grok.

Have fun and happy coding!


  1. Hi Wilbert,

    In order to use the git task .... does a git client "msysgit" have to be installed on the build server?

    How could I deal with passwords within the build script (when using https)



    1. I already uploaded version 0.2 as a binary to Github so you want have to compile it yourself. The link is

  2. No, when using the latest source there is no more need for an installed version of msysgit on the buildserver. Simply download the source and compile it (I've included an MSBuild script).

    I will upload new binaries soon to Github, so you wont have to compile your own version.

    I'm not quite clear what you mean with your last question. In my workflow I have read-only access to my repositories which I can access with both the HTTP and GIT protocol. See the example file in the source code for some concrete examples.

  3. Nice! Thanks for putting this together. I'm just git'ing started with git, but am totally impressed after a month. Don't want to ever go back to TFS. :) Trying to set up a build server for my own code and will try this out soon.



  4. Hi Wilbert,
    If i have to fetch the git code over using user credentials (uname/pass) then which api have to call.
    Should i have to modify clone method in your code section.


    1. The current version of the software does not support that. I don't need it for my requirements. (The buildserver has an account which can access the Git repositories - that is enough).


Post a Comment

Popular posts from this blog

Small tip: use QueueBackgroundWorkItem for asynchronous work in ASP.NET

Why you should use git merge --no-ff when rebasing.

Set default merge options for Git branches