git extensions for msbuild
This is an .net assembly with custom tasks for msbuild to handle common git commands.
A typical msbuild project has the following format
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text="This is my build" />
</Target>
</Project>
To import an assembly, use the <UsingTask>
element, specifying which class/taks you want to import
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--======================================================================-->
<UsingTask AssemblyFile="msbuild.git.dll" TaskName="msbuild.git.GitGetSHA" />
<!--======================================================================-->
<Target Name="Build">
<Message Text="This is my build" />
</Target>
</Project>
Then, just use the imported class/task
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="msbuild.git.dll" TaskName="msbuild.git.GitGetSHA" />
<Target Name="Build">
<!--======================================================================-->
<GitGetSHA Repository="c:\repos\myrepo" Branch="origin/master">
<Output TaskParameter="SHA" PropertyName="WhateverPropertyOfYourChoice" />
</GitGetSHA>
<!--======================================================================-->
<Message Text="HEAD of origin/master: $(WhateverPropertyOfYourChoice)" />
</Target>
</Project>
All taks require the parameter Repository="<path to repo>"
All tasks accept an optional attribute GitHome="<path to git>"
An example of a build project would look like this:
<Target Name="Build">
<GitClean Repository="$(Repo)" />
<GitReset Repository="$(Repo)" />
<GitCheckout Repository="$(Repo)" Force="true" Branch="master" />
<GitPull Repository="$(Repo)" />
<GitGetSHA Repository="$(Repo)">
<Output TaskParameter="SHA" PropertyName="Revision" />
</GitGetSHA>
<Message Text="This is my build revision: $(Revision)" />
<!--actually build something, then if it succeeds...-->
<GitTag Repository="$(Repo)" Commit="$(Revision)" Tag="MyBuildId" />
<GitPush Repository="$(Repo)" Tags="true" />
</Target>
GitAdd GitCheckout GitClean GitCommit GitGetSHA GitPull GitPush GitReset GitTag
<GitAdd Repository="c:\repos\myrepo" Path="path-to/file.txt" Force="true"/>
> git add --force -- "path-to/file.txt"
Path (optional): path to files to be added. See pathspec. Default: '.'
Force (optional): allows adding otherwise ignored files. See --force. Default: false
<GitCheckout Repository="c:\repos\myrepo" Branch="master" Track="true" Quiet="true" Force="true"/>
> git checkout --force --quiet --track "master"
Branch (required): what to checkout. Can be a commit or a branch name. See branch
Quiet (optional): quiet, suppress feedback messages. See --quiet. Default: false
Force (optional): when switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. See --force. Default: false
Track (optional): When creating a new branch, set up "upstream" configuration. See --track. Default: false
<GitClean Repository="c:\repos\myrepo" Quiet="true" Force="true"
UntrackedDirectories="true" EvenIgnoredEntries="true" Exclude="*.txt"/>
> git clean --quiet --force -d -x --exclude="*.txt*"
Quiet (optional): be quiet, only report errors, but not the files that are successfully removed. See --quiet. Default: false
Force (optional): See --force. Default: true
UntrackedDirectories (optional): remove untracked directories. See -d. Default: true
EvenIgnoredEntries (optional): remove ignored files too. See -x. Default: true
OnlyIgnoredEntries (optional): remove only ignored files. See -X. Default: false
Exclude (optional): do not clean these files. See --exclude
<GitCommit Repository="c:\repos\myrepo" Message="your commit message"/>
> git commit --message "your commit messsage"
Message (optional): commit message. See --message. Default: "Auto-commit from msbuild"
<GitGetSHA Repository="c:\repos\myrepo" Branch="master">
<Output TaskParameter="SHA" PropertyName="MyProperty" />
</GitGetSHA>
> git rev-parse "master"
Branch (optional): name of branch to retrieve the SHA hash. Default: "HEAD"
SHA (output): receives the sha1 hash of the selected branch
<GitPull Repository="c:\repos\myrepo" Quiet="true" Force="true"
Verbose="true" Rebase="true" Origin="myserver"/>
> git pull --quiet --force --verbose --rebase "myserver"
Quiet (optional): See --quiet. Default: false
Force (optional): See --force. Default: false
Verbose (optional): See --verbose. Default: false
Rebase (optional): rebase the current branch on top of the upstream branch after fetching. See --rebase. Default: false
Origin (optional): server to fetch/pull from. See repository. Default: "origin"
<GitPush Repository="c:\repos\myrepo" Tags="true" Target="myserver" Branch="mybranch"/>
> git push --tags "myserver" "mybranch"
Tags (optional): push tags. See --tags. Default: false
Target (optional): where to push to. See repository. Default: "origin"
Branch (optional): branch to push. Default: "HEAD"
<GitReset Repository="c:\repos\myrepo" Quiet="true" Mode="hard" Commit="origin/master"/>
> git reset --hard --quiet "origin/master"
Quiet (optional): be quiet, only report errors. See --quiet. Default: true
Mode (optional): reset mode. See mode. Default: hard
Commit (optional): the commit to reset to. Not used by default.
<GitTag Repository="c:\repos\myrepo" Force="true" Delete="false" Annotate="true"
Message="my commit message" Commit="c922c83" Tag="my_tag_name"/>
> git tag --force --annotate --message "my commit message" "my_tag_name" "c922c83"
Force (optional): replace an existing tag with the given name (instead of failing). See --force. Default: false
Delete (optional): delete existing tags with the given names. If used, Annotate, Message and Commit are ignored. See --delete. Default: false
Annotate (optional): make an annotated tag (meant for release). See --annotate. Default: true
Message (optional): optional commit message. See --message. Default: "Tag added automatically by msbuild"
Commit (optional): what to tag. See commit. Not used by default
Tag (required): name of tag to set. See tagname.