Monday, June 22, 2009

SPSource: Reverse engineering tool for SharePoint

SPSource is a tool for SharePoint developers to assist in the creation of WSS Solution Packages (WSPs) allowing for the use SharePoint Designer and the SharePoint web UI to make quick changes to items, then push those items into Visual Studio for later compilation into a WSP.

Some examples of what can be done using SPSource:
  • Completely define a custom Publishing Feature using SPD and the SharePoint UI, creating the master pages, page layouts, content types, style sheets, and images directly in the content database. Once at a point where it's ready for deployment, run SPSource against the project and pull everything into a pre-existing WSP. If changes are needed in the markup, make them using SPD, and re-run SPSource. The files in the WSP will be updated and ready for a solution upgrade.
  • Implement a class on an ASPX page (code behind) in SPD, and code that class in Visual Studio, or add custom server controls to the markup in SPD. Push your assembly directly to the GAC or bin as part of the build process, and the code-to-test time is much faster, as the markup files are already in the content database. Once everything is set, run SPSource again the project, and pull everything together into the WSP.
  • Add a custom Content Query Web Part (CQWP) .webpart file to the web part gallery, and change the properties and settings for the new CQWP via the UI and SPD to use custom XSL files that you add to the Style Library/XSL Style Sheets folder. Create new ItemStyles, change the Headers, or add new parameters to the Main XSL. The XSL files can be updated quickly using SPD, and changes can be seen right away. When all is ready for integration into the WSP, execute SPSource against the new files and create a new Feature for the new web part in minutes.
  • Create a complex List instance with Content Types and related Site Columns and reverse the whole lot out to a Feature to deployed to another environment as a Solution Package (wsp) using your favourite tool: VSeWSS, WSPBuilder or STSDev.
You can download it from here.

To use it you can make the following steps:

1. Create the following folder structure to mirror the 12 Hive folder structure:


2. Then create a folder for your Feature (which will deploy the List Template, Site Column and Content Type). For example at C:\temp\SPSource Demo\12\TEMPLATES\FEATURES\SPSourceDemoFeature.


3. Create a Feature.xml file

Create a Feature file at C:\temp\SPSource Demo\12\TEMPLATES\FEATURES\SPSourceDemoFeature\feature.xml file and place the default feature XML content in the file:

<Feature

Id="863BBC74-939E-4296-A538-931369C04433"

Title="SPSource Demo Feature"

Description=""

Version="1.0.0.0"

Scope="Site"

Hidden="False"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

</ElementManifests>

</Feature>


4. Create the .spsource file

Create a new .spsource file e.g. ‘C:\temp\SPSource Demo\12\TEMPLATES\FEATURES\SPSourceDemoFeature\lists.spsource’. The content of this file reflects the base schema for the Elements Manifest. So start with:


<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

</Elements>

Because we want to reverse engineer the Site Column, Content Type and List you will need two elements in here. One to point to the List and one to point to the Content Type.

NOTE: Any associated Site Columns on the Content Type will automatically be reverse engineered.


<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ListTemplate Name="Documents" />

<ContentType Name="Demo Document" />

</Elements>



5. Run SPSource

Now that you have set up the folder for SPSource to run, you now need to execute SPSource.

Open up a command prompt window and type:

Cd C:\temp\SPSource Demo

This will take you to the folder where you’ve created your files (if you chose a different name please adjust this).

Then simply type:

"C:\Program Files\SPSource \SPSource.exe" -designsite http://win-0xqbnqw37uf:41508/sites/DevDemo

NOTE: If you chose a different location for SPSource when you installed it you will have to modify this.