Easily extend post-commit hook in Subversion using NAnt – email anyone?

There are several scripts floating around the Net regarding publishing an email to the development list every time someone commits a revision to Subversion.

In other cases, you may want to post the commit log entry directly to your project tracking system, such as trac, Rally, Gemini, Mingle, etc.  Anything under the sun can be coded into a post-commit action with Subversion.

Here’s how it works.  Here is how to send post commit email from Subversion while running on Windows:

In your subversion repository, there is a hooks folder.  This contains some template files for you.  On a Windows system, you’ll want a file called post-commit.bat.  This batch command will be run immediately after Subversion commits a transactional revision to the repository.  You can do work on other events, but I’ll focus on post-commit for this post.

Here is my post-commit.bat file that will call NAnt (which is placed inside the hooks folder for simplicity):

 

pushd .
cd DRIVELETTER:svnrepositoriesrepositorynamehooks
nantnant.exe -buildfile:postcommitemail.build -D:path.repository=%1 -D:revision=%2 > lastpostcommitrun.txt
popd

 

Notice how we are merely calling nant.exe.  The rest of the interesting work is done by NAnt.  Now that we are within NAnt, we can script out any action we might need.  In this case, I’m going to use some SVN command line tools to build up a simple email that with send developers what was included in the last commit:

 

<?xml version="1.0" encoding="utf-8"?>
<project name="commit" default="build" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
    <target name="build">

        <exec program="svnlook" commandline="author ${path.repository} -r ${revision}" output="author.txt"/>        
        <exec program="svnlook" commandline="info ${path.repository} -r ${revision}" output="message.txt"/>
        <echo message=" " file="message.txt" append="true"/>
        <exec program="svnlook" commandline="changed ${path.repository} -r ${revision}" output="message.txt" append="true" />
        <exec program="svnlook" commandline="diff ${path.repository} -r ${revision} --no-diff-deleted --no-diff-added" output="message.txt" append="true"/>
        
        <loadfile file="author.txt" property="author"/>
        <loadfile file="message.txt" property="message"/>
        <mail tolist=jeffrey@mydomain.com
            from=build@mydomain.com 
            subject="SVN ${path.repository} - ${author}" 
            message="${message}" 
            mailhost="smtp.mydomain.com"/>
    </target>

</project>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

That’s all it takes.  I can write anything I need to in order to perform custom actions when things happen with my Subversion repository.  In this case, I’m sending email to a list, and the email contains the last commit.

MvcContrib now has IoC container support for “the big 3”

If you are interested in more information on MvcContrib as it happens, subscribe to my feed:  http://feeds.feedburner.com/jeffreypalermo 

It hasn’t even been 48 hours since the release of the public CTP of the ASP.NET MVC Framework, but already, the community has contributed IoC container support for Windsor, StructureMap, and Spring.Net to the MvcContrib open source project.  This project exists to provide extended functionality for use with the ASP.NET MVC Framework.

Many thanks for the patches.

We do need documentation contribution as well as samples.

Headspring advanced .Net developer training available in Austin, TX (by yours truly)

.NET Boot Camp: From Journeyman to Master Series

This course will take competent .NET software developers and propel them towards becoming a master developer.

January 30, January 31, and February 1
From 8 a.m. to 6 p.m.
Click here for all the details

This advanced curriculum will cover everything involved in developing software in .NET, from setting up a new project and defining the architecture to implementing functionality in a loosely-coupled and testable manner. We will immerse ourselves in domain-driven design, test-driven development, design patterns, object-relational mapping, inversion of control (IoC), pair programming, automated builds, and continuous integration (CI). Students will discover which practices cause projects to fail and which practices help projects succeed. The course will include a strong focus on solid principles and values that can be applied to any .NET project. With a solid understanding of Agile values and object-oriented programming, students will emerge from the training with a refocused view on software development and the tools to immediately bring value back to their companies. All developers will take back working code developed during the course using the techniques and practices taught.

Call HeadspringJeffrey Palermo is the CTO of Headspring Systems. He specializes in doubling the productivity of software teams by introducing solid principles, values, and discipline. Along with holding the MCSD.NET certification and Solutions Architect MVP award, he also runs the Austin .NET User Group, is a board member of AgileAustin, and is a speaker on the INETA Speakers’ Bureau. He is a graduate from Texas A&M University, an Eagle Scout, and an Iraq war veteran.

Call Headspring

 

 

 

 

If you are looking for a course to learn more about .Net itself, I highly recommend JP Boodhoo’s course in College Station, TX at the beginning of January.   The above course assumes a strong understanding of .Net and is intended to take someone already well-versed with .Net and bring in the concepts and practices that will take them to the next level.

MvcContrib open source project call for participation

To keep up with this, subscribe to my feed:  http://feeds.feedburner.com/jeffreypalermo

As you’ve read in plenty of other places by now, the CTP of the ASP.NET Extensions is now available for downloadHere is a direct link.

Eric Hexter and I have started an open source project to contribute to and extend the ASP.NET MVC Framework.  There are things that Microsoft is not going to bundle with the official release (like IoC container support for Windsor, StructureMap, Spring.Net, etc), so the goal of this project is to add other useful features as determined by the community.

 

Go to http://mvccontrib.org.  There are links to the Subversion trunk for the project, and there is an issues list we are using for a backlog.  Anyone logged into CodePlex can contribute an idea to the backlog (issues list), and anyone can upload a patch for acceptance.  We’re pretty open to patches, but the one strict requirement is that all code submitted must come with full NUnit test coverage and be submitted as a patch file compatible with TortoiseSVN.

We’ll also need to provide documentation and samples for how to use the features contributed to MvcContrib, so even if you don’t want to contribute code, we could also use samples contributed.

ASP.NET MVC Framework CTP is now available – MvcContrib also available

To keep up with this, subscribe to my feed:  http://feeds.feedburner.com/jeffreypalermo

The long-awaited MVC Framework public CTP is available for download here:

http://asp.net/downloads/3.5-extensions/  — Here is a direct download link.

Check out Scott Guthrie’s MVC info here.  Brad Abrams announcement here.

To get some more View helpers that didn’t make it into the CTP (but will), download the mvctoolkit

http://asp.net/downloads/3.5-extensions/MVCToolkit.zip

And download MvcContrib, which gives you IoC container support for controllers as well as whatever the community deams appropriate.  If you have an opinion about what else should be offered with MvcContrib, come and add to the backlog list.   Who knows, some of these features might even make it into the actual product from Microsoft.

New NAnt beta release supports .Net 3.5/Silverlight – v0.86 beta 1

My company uses a combination of NAnt and MSBuild for build automation and some deployments.  We use MSBuild for purely Microsoft tool execution, like compiling.  We use NAnt for everything else, like moving files, packing the release, versioning, and everything else under the sun.  This solution is working very well for us, and I’ve used NAnt in major scenarios for over two years now. 

I’m very happy to share that the team has just released beta1 of version 0.86.  Go to the NAnt website to download it now or you can download it more directly here.  Read the full release notes here, but I want to highlight the more interesting things that came down the NAnt users list:

Support matrix for NAnt 0.86 beta 1

Framework                     Target      Runtime
—————————————————-
.NET Framework 1.0              *            *
.NET Framework 1.1              *            *
.NET Framework 2.0              *            *
.NET Framework 3.5              *            *
.NET Compact Framework 1.0      *
.NET Compact Framework 2.0      *
Mono 1.0 Profile                *            *
Mono 2.0 Profile                *            *
Mono 3.5 Profile                *            *
Moonlight 2.0                   *
Shared Source CLI 1.0           *
Silverlight 2.0                 *

 

To me, the big ones are .Net 3.5 and Silverlight 2.0 support.  Up to now (it’s only been a few weeks since .Net 3.5 was released) I used my own modification to the NAnt config file to make the build work with .Net 3.5, but I’ve pulled that out and am now using the beta 1 release.

For those wondering whether they should use it:  I just upgraded the MvcContrib open source project, and our build worked just fine.  It’s not hard to find out if there are any issues with your build.  Drop it in and run the build.  If there are any problems, revert your working copy. 

I would like to publicly express appreciation for the developers who are working on NAnt.  There are lots of users of the tool out there, including me, and I thank you for your contributions to the developer community.

ASP.NET MVC CTP, podcast, and mvccontrib open source project

As Scott Guthrie has stated, Microsoft is hoping to release the first public CTP of the ASP.NET MVC Framework tomorrow.  This is very exciting.

If you are interested, you can listen to a podcast Craig Shoemaker recorded with me on the ASP.NET MVC Framework.

Also, there is a new open source project forming.  It’s mvccontrib.  You can go there through this link.  There is no release yet (or code), but with the CTP going public, this project is being kicked off, and we are looking for people interested in submitting patches.  Show enough interest by submitting multiple patches, and we’ll make you a committer (that’s the way open-source works).

Who is to say that my knife is too sharp for my own good?

At DevTeach this past week, I had some great conversations, but one in particular is the conversation that many people have had:  about using sharp tools.  A common thought we come across is that a vendor or someone in management decides that the software team should be restricted in some way for their own good.  If this measure isn’t taken, the software team could hurt themselves or the software could come out wrong.  Some of the analogies used are:

  • Running with scissors
  • Unsafe tools
  • If given a sharp knife, you might cut yourself.

These can be applied to many environments.  For instance, an argument against dynamic languages is that without compile-time checking, errors won’t be found until runtime.  If developers are allowed to use dynamic languages for _real_ projects, then the software would fail because we don’t know if it works until we run it.  (I won’t bother replying to common arguments, but I invite readers to give their reply in the comments).

Unsafe tools could be IDE features, frameworks, libraries, or even permitted architectures.  For instance, if we use 3rd party libraries or frameworks, developers might hurt themselves.  Better stick to what comes from Microsoft.

Then, like children, I’ve heard that developers might cut themselves if given a sharp knife.

I credit 100% of the dysfunction of these thoughts to managers who allow or encourage these thoughts in their organizations.  Being a software manager myself, I know that I’m paying quite a bit for good developers.  I’m not paying for children, so I’m certainly not going to give them safety scissors, blunted markers or non-toxic playdough.  Developers should be adults, not children.  By the way, if you encounter developers who aren’t professional adults, then HR functions should step in.  I want to give my developers the best, sharpest tools possible.  They might hurt themselves or the company?  There are other ways to manage that risk other than giving developers safety scissors.

I was reminded of these conversations by a blog post by Oren Eini, with whom I spoke about this issue at DevTeach.  Oren came up with the following logo, which enumerates that one of the facets of the spirit of Alt.Net is that developers are professionals, and if there is a need to run with Scissors amids flying bullets, then they are capable of making that decision.

Chad Myers quickly condensed it down to the badge that I’ve added to my blog: