Using MSBuild to Create a SharePoint WSP File On Build

Posted Tuesday, August 28, 2007 3:58 PM by C-Dog's .NET Tip of the Day

This has been posted by a few others, but I wanted to make sure people knew about it. It is pretty simple to have Visual Studio create a WSP file for you every time you compile using MSBuild. Start by creating an XML file called Solution.build (or whatever). I typically put this in my Solution folder. This is going to simply execute the makecab.exe file with a path to your solution.ddf file (also typically in the Solution folder). It should look like this.

<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="DesktopBuild" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="BuildSolutionPackage">
    <Exec Command="makecab.exe /F solution/cab.ddf"></Exec>
  </Target>
</Project>

The target name can be anything, just make a note of it because you will reference it when editing your .csproj file (your are using C# right?). This is the part that kind of sucks. Go edit your .csproj file with the text editor of your choice (i.e. notepad). Go to the end and look for the import statements and you'll see some post build type things commented out. That is where you want to paste the following.

<Import Project="Solution\Solution.build" />
<Target Name="AfterBuild">
  <CallTarget Targets="BuildSolutionPackage" />
</Target>

This is where the Target name has to match up. Once you do that, reload the project in Visual Studio. You'll get prompted for security or something because you customized the file. Just ignore it and move on. Now when you compile, it will make the .wsp file for you.

Eventually my goal is to figure out how to make some Team Build scripts for our MOSS solution. I think this is a step in the right direction. When I figure that out, I will post more on it. I also think there are some guidance packages out now that help with this but I have yet to find anything I really like yet. Maybe I will create my own someday.

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=382

Filed under: ,