Tuesday, October 17, 2006

Anatomy of a SharePoint WSS v3 Feature Project in Visual Studio 2005


In a previous post, I published the source code to a WSS v3 Feature which illustrates how to add sub menus to SharePoint's Site Actions menu. In this follow-up post, I'll walk through the anatomy of the Visual Studio 2005 project for this feature.

Artifact 1 - Modified class library project

This is a standard C# Class Library project modified to include the Feature.build project (artifact 4) and call Feature.build's BuildFeaturePackage target from the AfterBuild target. Note that this project references Microsoft.SharePoint.dll and System.Web.dll.

1 <Import Project="feature.build" />
2 <Target Name="AfterBuild">
3 <CallTarget Targets="BuildFeaturePackage" />
4 </Target>

Artifact 2 - Inclusion of SharePoint's XML Schema Definitions

References to these SharePoint XML Schema Definitions add Intellisense for Elements.xml (artifact 3), Feature.xml (artifact 5) and Manifest.xml (artifact 7).

Artifact 3 - Elements.xml

Element manifest file containing definitions to the feature's elements. This manifest file is referenced from Feature.xml (artifact 5). See this blog post for details on the contents of Elements.xml.


Artifact 4 - Feature.build

Custom MSBuild project used to create the WSS Solution Package for deployment of the feature. Feature.build calls MakeCab.exe, which can be downloaded with the Microsoft Cabinet SDK. For the Exec call (line 6) to work, MakeCab.exe is expected to be located in the system path.


1 <?xml version="1.0" encoding="utf-8" ?>
2 <Project DefaultTargets="BuildFeaturePackage" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
4 <Target Name="BuildFeaturePackage">
5 <Copy SourceFiles="$(TargetPath)" DestinationFolder="bin" ContinueOnError="false"/>
6 <Exec Command="makecab.exe /F package.ddf /D CabinetNameTemplate=$(TargetName).wsp" />
7 </Target>
8
9 </Project>
10

Artifact 5 - Feature.xml

Defines the feature and specifies the location of assemblies, files, dependencies, or properties that support the Feature. See this blog post for details on the contents of Feature.xml.


Artifact 6 - Public/Private key pair

Signs the feature's code-behind assembly so that the assembly can be placed into the Global Assembly Cache (GAC).


Artifact 7 - Manifest.xml

Defines the list of features, site definitions, resource files, web part files, and assemblies to be included in the Solution package. In this case, just a feature and its code-behind assembly are defined.


1 <?xml version="1.0" encoding="utf-8" ?>
2
3 <Solution SolutionId="{5DA74A52-818A-4bba-B268-AD5E29361489}"
4 xmlns="http://schemas.microsoft.com/sharepoint/">
5
6 <FeatureManifests>
7 <FeatureManifest Location="SiteActionsSubMenuDemo\Feature.xml"/>
8 </FeatureManifests>
9
10 <Assemblies>
11 <Assembly DeploymentTarget="GlobalAssemblyCache"
12 Location="SiteActionsSubMenuDemo.dll">
13 <SafeControls>
14 <SafeControl Assembly="SiteActionsSubMenuDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9db3057acd9c0f6"
15 Namespace="SiteActionsSubMenuDemo"
16 TypeName="*"
17 Safe="True" />
18 </SafeControls>
19 </Assembly>
20 </Assemblies>
21
22 </Solution>


Artifact 8 - Package.ddf

Package.ddf is a MakeCab diamond directive file used to define the structure and contents of the solution package.
1 ;*** MakeCab Directive file
2 ;
3 .OPTION Explicit ; Generate errors
4 .Set DiskDirectoryTemplate=CDROM
5 .Set CompressionType=MSZIP
6 .Set UniqueFiles=Off
7 .Set Cabinet=On
8 .Set DiskDirectory1=Package
9 ;
10 ; \
11 ;**************************************************
12 manifest.xml
13 bin\SiteActionsSubMenuDemo.dll
14
15 .Set DestinationDir=SiteActionsSubMenuDemo
16 Feature.xml
17 Elements.xml
18 ;
19 ;***End

Artifact 9 - SiteActionsSubMenuCustomizer.cs

Referenced from the CustomAction located in Elements.xml (artifact 3), this C# class defines the structure of the sub menus which will be added to the Site Actions Menu. See this blog post for details on the contents of SiteActionsSubMenuCustomizer.cs.

The complete Visual Studio 2005 solution can be download here:

Source: QuickSiteSettingsFeature_src.zip (21.5KB)

For a basic step-by-step walk through on creating, installing and activating custom actions that will be located on the Site Actions dropdown menu, see Darrin Bishop's post Custom Actions - Simple Steps to Add Your Touch to Site Actions.

Categories: , , , , , ,

5 comments:

telex said...

Hey, this guy has packaged all this wizardry into a VS solution template:
http://blog.thekid.me.uk/2007/01/27/a-new-sharepoint-solution-deployment-project-template-2/

ICEFIR3 said...

Hi I'm having problems getting the solution to package itself automatically. Can you possibly elaborate on the packaging process?

I tried simply compiling the solution from your source and it doesn't create the new wsp file...

Any thoughts, insight?

Anonymous said...

Is there anywhere on the net that specifically defines each element and attribute available when creating a manifest.xml file?

Anonymous said...

Where did this Feature project template come from? I've tried VSeWSS 1.0 and 1.1 and neither of them have a feature project template.

Thanks.

Anonymous said...

Where did this Feature project template come from? I've tried VSeWSS 1.0 and 1.1 and neither of them have a feature project template.

Thanks.