in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

MSBuild Task for SharePoint - MakeCab

I've been doing quite a bit of SharePoint lately, and I feel there is still too much repetitive, manual effort involved in creating SharePoint solutions. One has to first create an empty class library project, and then add the folder structure and feature.xml, elements.xml, manifest.xml and wsp.ddf files. Next you have to keep track of file locations, both inside the solution and in the feature directory, and write post-build events to handle creation and dev deployment.

I have it in my mind to create a Visual Studio extensibility project to automate a lot of this stuff and provide visual designers to handle a lot of the grunt work. But that is a much larger task, so for now I am releasing my MakeCab task for MSBuild.

For those who are not familiar, the Microsoft Build Engine (MSBuild) is the underlying engine for building .NET solutions. It is available both as a command line utility, and as the hosted build tool for Visual Studio. MSBuild uses project files (.*proj) as input and they are xml based. The xml structure mainly contains Items, Properties, Targets and Tasks.

What I have written is a simple Task to execute MakeCab for a given .DDF file. The process is pretty simple: inherit from Microsoft.Build.Framework.Task and override the Execute method. Then I added a Required public property for the directive file input, and utilized that to create and run a System.Diagnostics.Process.

public class MakeCab : Task
{
    private string directivesFile;

    public
override bool Execute()
    {
        try
       
{
            Log.LogMessage("Executing MakeCAB for " + directivesFile);

            ProcessStartInfo si = new ProcessStartInfo("makecab");
            si.Arguments = "/f " + directivesFile;
            Process.Start(si);

            Log.LogMessage("Execution of MakeCAB succeeded for " + directivesFile);

            return true;
        }
        catch (Exception ex)
        {
            Log.LogMessage("Execution of MakeCAB failed for " + directivesFile +
                ". Reason: " + ex.Message);
            Log.LogError(ex.Message);
            return false;
        }
    }

    [Required]
    public string DirectivesFile
    {
        get
       
{
            return directivesFile;
        }
        set
       
{
            directivesFile = value;
        }
    }
}

I also signed my assembly and created a post-build event to register it in the GAC. The final step was to add the necessary nodes into the project xml file…

<UsingTask TaskName="PlatinumBay.MSBuild.MakeCab.MakeCab"
   
AssemblyName="PlatinumBay.MSBuild.MakeCab, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9805384e45235b26" />
<
Target Name="MyMakeCab">
   
<
MakeCab DirectivesFile="wsp.ddf" />
</
Target>

…and add my new target to the DefaultTargets attribute:

<Project DefaultTargets="Build;MakeCab"
    
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

And that's it. Now when I build my project, my cabinet file gets created.

You can download the bits from the downloads section.

Download Source
Download Compiled
 

Published Nov 26 2007, 01:50 PM by Steve
Filed under: ,

Comments

November 26, 2007 10:16 PM

MSBuild MSBuild Task for SharePoint - MakeCab [Via: Steve ] ASP.NET Ajax with the ASP.NET MVC Framework...

 

November 26, 2007 10:16 PM

Link Listing - November 26, 2007

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews has been working as a developer for more than 8 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. He has firsthand developer experience with a variety of languages, including Java, VB, and .NET. Most recently, he has been immersed in SharePoint. He is currently employed at RDA Corporation in Philadelphia, PA, as a Software Engineer and a team member in the Architectural Guidance evangelism team. Steve is also an MTCS (x2), ICSOO, and .NET fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.