Minneapolis Office Developer Interest Group (MODIG) February 21, 2008 Solutions and Feature Development Neil Iversen Inetium http://justaddcode.com/

Download Report

Transcript Minneapolis Office Developer Interest Group (MODIG) February 21, 2008 Solutions and Feature Development Neil Iversen Inetium http://justaddcode.com/

Minneapolis Office Developer Interest
Group (MODIG)
February 21, 2008
Solutions and Feature Development
Neil Iversen
Inetium
http://justaddcode.com/
The Plan


Introduction
 You are here
Feature Presentation



Solutions and Features
Next Topic Selection
Random Stuff
User Group Goals




Provide a community for SharePoint Developers
Share development knowledge
Exchange tips/tricks/other
Understand SPUtility as a metaphor for life
User Group Format

Presentations



Highlights of Nifty Things


1-2 per meeting
Hopefully Demo Heavy
See next slide
QA/Discussion/Random Things
Call for Cool Stuff

Created something cool?


Send Screenshots or Videos
We’ll try to feature some items here
Sharepointmn.com/pages/modig.aspx





Our current home
Convenient URL
Meeting information
Previous presentations
Running on SharePoint

As required by SharePoint User
Group Law
Upcoming

Next Meeting



Week Of: March 17-20 (Watch your email)
Topic: TBD – Hopefully later today
MNSPUG


March 12 (9:00am – Noon)
Topic : TBD (sharepointmn.com)
Solutions and Features









Feature Intro
Feature Limitations
Custom Actions
Dealing with Dependencies
Stapling
Managing Files
Feature Receivers
Solutions
Questions
Feature Introduction


Deployment vehicle for SharePoint applications
The Goal


Setup.exe style deployment
The Reality

Not exactly
Feature Introduction

Ability to customize SharePoint


Actions



Install/Uninstall
Activate/Deactivate
Stored in the Hive



Used extensively by SharePoint itself
12\TEMPLATE\FEATURES
Separate directory for each feature
Scopes
Web, Site, Farm, Web App
Common Scenarios




List Templates
Workflow
Key Feature Limitations




Limited set of supported schemas
Supports fewer file options than Solutions
Must be bundled in Solutions for larger farms
Upgrading\Removing deployed features is difficult

Might not follow expected behavior
Feature Lifecycle

Normal Behavior
Installed

Activated
Deactivated
Uninstalled
Farm Behavior
Installing
• Installed
• Activated
Uninstalling
• Deactivated
• Uninstalled
Custom Actions



Create your own menu options
Many extensibility points
Main Attributes





Title
Location
GroupId
Sequence
HideCustomAction

Hides an existing Custom Action
Custom Actions

URL Prefixes



URL Replacements





~site – Relative link to the SPWeb
~sitecollection – Relative link to the SPSite
{ItemId} – List Item’s ID
{ItemUrl} – List Item URL
{ListId} – ID of the List
{SiteUrl} – Like ~site except it can be used anywhere
Example
<CustomAction
Id="325b7c78-f041-4d1b-856b-f9b1e49ddfeb"
GroupId="PersonalActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title=“My Title"
Description=“A Custom Action
<UrlAction Url=“javascript:alert(‘You were at {SiteUrl}’);"/>
</CustomAction>
Managing Files in Features

Deploy a file into a site



URL can be aliased




Web
Document Library
MobileRedirect (\m) uses it
Not as powerful as Solutions
Uninstall behavior is non-intuitive
Example:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name=“file" Url=“” Path=“”">
<File Url=“MyFile.aspx" />
</Module>
</Elements>
Demo: Features and Files
Dealing with Dependencies



Problem: Feature depends on another SharePoint
Object
Solution: Create dependency between the features
Example
<ActivationDependencies>
<ActivationDependency FeatureId="52890518-036f4027-babd-f4c7df3ee429" />
<ActivationDependency FeatureId="6d276cfc-1c8446cc-8566-500e66213e06 " />
</ActivationDependencies>

Dependency Limitations

Feature Chains


Dependencies can’t be triggered at a higher scope


Ex: Farm Feature can’t depend on a Web Feature
Features can’t be automatically activated at different
scopes


Limited to one visible feature
Ex: Web Feature can’t activate a Farm Feature
Hidden Features





Automatically Activated for Dependencies
Automatically Deactivated when the last Dependency is Deactivated
Can’t be depended on in different scopes
Can’t have their own dependencies
Can add an additional level to Feature Chains
Stapling



Problem: Can’t customize out of the box Site
Definitions
Solution: Stapling!
Scopes: Farm, Web App, Site


Note: Not Web
FeatureSiteTemplateAssociation

<FeatureSiteTemplateAssociation Id="b04e59b1-2c21-48fa-9497470b1ab711b0" TemplateName="STS#0" />

<FeatureSiteTemplateAssociation Id="fd45b13f-6334-4bce-b87c-49e3f820a74c"
TemplateName=“GLOBAL#0" />
Site Template (STS#0)
OOB Features
• teamcollab
• eventslist
•…
Stapled Features
(FeatureSiteTemplateAssoc)
• My Stapled Feature
Demo: Stapling in Action
Feature Recievers


The ‘Custom’ Feature
.NET Code

Override



FeatureInstalled, FeatureUninstalling
FeatureActivated, FeatureDeactivating
Example

<Feature Id="0a7e1ca9-ee71-4407-80a0-b5b57f4f6f5d"
Title=“My Feature Reciever"
Scope="Site"
ReceiverAssembly=“MyAssembly,Version=1.0.0.0, Culture=neutral,
PublicKeyToken=e35a4d2663eae0ae"
ReceiverClass=“MyAssembly.MyFeatureReciever"
xmlns="http://schemas.microsoft.com/sharepoint/">
Feature Receivers – Getting Context

Getting Context

Retrieving the Current Scoped Object

SPFeatureReceiverProperties


Cast to the appropriate type


SPFeatureReceiverProperties.Feature.Parent
Scope: Web
 SPWeb web = (SPWeb)properties.Feature.Parent;
 SPSite site = (SPSite)properties.Feature.Parent
Example Usages





Perform clean uninstalls of features
‘Upgrade’ features using Activate
Set dependencies to chain actions together
Web.config changes
Address gaps in current supported Features

Policies, Custom Fields, …
Feature Recievers - Debugging


Based on Deployment/Activation Method
Stsadm




Web Interface




Runs as currently logged in user
Debug/Console.WriteLine
System.Diagnostics.Debugger.Launch();
Runs as App Pool user
Need to use logger (EventLog, or some Logging code)
Attach to w3wp.exe
DLL Deployment



Overwrite Existing DLL
iisreset
stsadm –o activatefeature -force
Feature Properties




Configuration for your Feature
Allow different values for Dev/Test/Prod
Combine with scoped property bags to set
configurations
Example
<Properties>
<Property Key=“MyKey" Value=“123" />
<Property Key=“DBServer" Value=“prodsql001" />
</Properties>
DEMO: Deploying SPWeb Properties
Manually Activating Features

Why?




Evade chaining restrictions (at your own peril)
Working with Hidden Features
Manage Stages of a Site with a Web Part
Creating a ‘Suicide Feature’
Manually Activating a Feature

Get your Context


Find the Feature Collection


Ex: SPWeb.Features
Find the Feature’s Guid


Ex: SPWeb
Ex: Guid featureGuid = new Guid(“0a7e1ca9-ee71-440780a0-b5b57f4f6f5d”)
Activate!

Ex: SPWeb.Features.Add(featureGuid)
Solutions



Replaces copying files across servers
…with creating XML/DDF files
Can Easily Deploy







Multiple Features
Web Parts
Assemblies (GAC or BIN)
SafeControls
Code Access Security Settings
Plain Files
Farm Safe
Anatomy of a Solution

Manifest.xml



XML to define what you want SharePoint to do
Needs to be included in the DDF
The DDF



Defines what ‘makecab’ cabs
Slightly headache inducing file format
WSP == CAB
Demo: Solutions at Work
Summary



Features are Nifty
Solutions are Useful
Getting full value from either has a learning curve
Questions?
Next Meeting Planning

Possible Topics



PowerShell and SharePoint for Developers
Extending SharePoint with Custom Fields (Column Types)
…
Random Stuff
Feedback Forms/Giveaway
Mingle, Eat, Feedback
See you next time!
Neil Iversen
Inetium
http://justaddcode.com