470 likes | 601 Views
Code Camp NZ 2011. # CCNZ. www.mscommunities.co.nz. Deploying SharePoint Solutions and Features. Wayne Ewington Microsoft New Zealand. Who is Wayne Ewington?. Principal Consultant, Microsoft New Zealand SharePoint since Tahoe, NCompass Resolution 4.0 “ R5” July 2010
E N D
Code Camp NZ 2011 #CCNZ www.mscommunities.co.nz
Deploying SharePoint Solutions and Features Wayne Ewington Microsoft New Zealand
Who is Wayne Ewington? • Principal Consultant, Microsoft New Zealand • SharePoint since Tahoe, NCompass Resolution 4.0 • “R5” July 2010 • wayne.ewington@microsoft.com • http://blogs.msdn.com/b/waynewin • When I get time (which isn’t that often)
Agenda • Overview • Features and Lists • Feature Events • Feature Dependencies • Feature Stapling • Updating Solutions and Features
What Are They? • Feature: “Collection of SharePoint elements” • Solution: “Deployable and reusable way to bundle components that extend SharePoint”
So What! • Deployment should be a Design Goal .wsp .wsp Install Customisations Web Farm
Installing and Deploying Solutions Web Farm Add Server Add Solution Deploy Solution .wsp SP Admin Central Admin .wsp .wsp Config DB
Sandboxed SolutionsSolution catalog • New catalog available in the site collection level • _Catalogs/solutions • Contains the sandboxed solutions for particular site collection deployed by users
Creating Solutions SP Project Items MakeCab.exe Manifest.xml .wsp CAB.ddf
Manifest.xml manifest.xml Activation Dependencies ApplicationResourceFiles Assemblies CodeAccessSecurity DwpFiles FeatureManifests Resources RootFiles SiteDefinitionManifests TemplateFiles
Manifest.xml <SolutionSolutionId="4AFC1350-F354-4439-B941-51377E845F2B" xmlns="http://schemas.microsoft.com/sharepoint/"> <FeatureManifests> <FeatureManifestLocation="CodeCamp\feature.xml"/> </FeatureManifests> <TemplateFiles> <TemplateFileLocation="1033\xml\webtempcodecamp.xml"/> </TemplateFiles> <Assemblies> <AssemblyDeploymentTarget="GlobalAssemblyCache" Location="CodeCampFeatureReceiver.dll"/> </Assemblies> </Solution>
CAB.ddf .OPTION EXPLICIT .Set CabinetNameTemplate=CodeCamp.wsp ; All cabinets go in a single directory .set DiskDirectoryTemplate=CDROM ;** All files are compressed in cabinet files .Set CompressionType=MSZIP .Set UniqueFiles="ON" .Set Cabinet=on .Set DiskDirectory1=Package build \manifest.xml manifest.xml build \CodeCamp\feature.xml CodeCamp\feature.xml ...
SharePoint Solutions demo
Activating Features Web Farm Feature.xml Activate Feature Browser Content DB
What can you do with Features? • Custom Actions • Controls • Workflows • Fields (Site Columns) • Content Types • List Templates • List Instances • Web Templates • Deploy Files
Feature Scopes Farm Web Application Site Collection Sandbox Solutions Web Site
Feature.xml <?xmlversion="1.0"encoding="utf-8"?> <FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" Title="$Resources:core,documentlibraryFeatureTitle;" Description="$Resources:core,documentlibraryFeatureDesc;" Version="1.0.0.0" Scope="Web" Hidden="TRUE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifestLocation="ListTemplates\DocumentLibrary.xml"/> </ElementManifests> </Feature>
Features and Lists • Field Columns • Content Types • List Templates • List Instances
Feature.xml <?xmlversion="1.0"encoding="utf-8" ?> <Feature Id="68C88F67-CF32-4474-8F42-9C89D8465395" Title="Code Camp List" Description="Code Camp List Feature" ... > <ElementManifests> <ElementManifestLocation="FieldTypes.xml"/> <ElementManifestLocation="ContentTypes.xml"/> <ElementManifestLocation="ListDefinitions.xml"/> <ElementManifestLocation="ListInstance.xml"/> </ElementManifests> </Feature>
Field Types (Site Columns) <?xmlversion="1.0"encoding="utf-8" ?> <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <Field ID="{714A856F-127A-40a3-9628-58906B51B048}" Name="FullName" DisplayName="Full Name" Group="Code Camp Columns" Type="Text" MaxLength="100" Hidden="False" Required="True" SourceID="http://schemas.microsoft.com/sharepoint/v3" /> </Elements>
Content Types <?xmlversion="1.0"encoding="utf-8" ?> <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <ContentType ID="0x01001ABBAD4652DE4CCEAB3C270F1DFD5F86" Name="Code Camp Content Type" Description="This is a Code Camp Content Type" Group="Code Camp"> <FieldRefs> <FieldRefID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}" Name="LinkTitle"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}" Name="LinkTitleNoMenu"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"Name="Title"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{BABE2FC9-19C5-4310-8DE2-2C365770EE62}" Name="QuoteAuthor"DisplayName="Author Name" Required="TRUE"/> <FieldRefID="{F005C9BF-D147-428b-AAEA-9D343CBB39F0}" Name="DateUsed"DisplayName="Date Last Used" Format="DateOnly"/> </FieldRefs> </ContentType> </Elements>
Content Types 0x01001ABBAD4652DE4CCEAB3C270F1DFD5F86 Separator GUID Base Type Provides an inheritance model
Content Types <?xmlversion="1.0"encoding="utf-8" ?> <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <ContentType ID="0x01001ABBAD4652DE4CCEAB3C270F1DFD5F86" Name="Code Camp Content Type" Description="This is a Code Camp Content Type" Group="Code Camp"> <FieldRefs> <FieldRefID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}" Name="LinkTitle"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}" Name="LinkTitleNoMenu"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"Name="Title"DisplayName="Quote Text" Sealed="TRUE"Required="TRUE"/> <FieldRefID="{BABE2FC9-19C5-4310-8DE2-2C365770EE62}" Name="QuoteAuthor"DisplayName="Author Name" Required="TRUE"/> <FieldRefID="{F005C9BF-D147-428b-AAEA-9D343CBB39F0}" Name="DateUsed"DisplayName="Date Last Used" Format="DateOnly"/> </FieldRefs> </ContentType> </Elements>
List Templates <?xmlversion="1.0"encoding="utf-8" ?> <ElementsId="5315E35D-BCA7-4a9f-A77D-EF62E01D437D" xmlns="http://schemas.microsoft.com/sharepoint/"> <ListTemplate FeatureId="68C88F67-CF32-4474-8F42-9C89D8465395" Name="TechEdList" DisplayName="TechEd List" Description="List for TechEd." Type="10001" BaseType="0" OnQuickLaunch="False" SecurityBits="11"/> </Elements>
Schema.xml • List URL • Content Types • Fields • List Content Types • Views • Forms • View, Edit, and Create • Copy an existing Schema.xml and modify • VS.NET 2010 is even easier!!! <?xmlversion="1.0"encoding="utf-8"?> <ListTitle="TechEd List"Url="Lists/TechEdList"BaseType="0"FolderCreation="FALSE"DisableAttachments="True"xlmns="http://schemas.microsoft.com/sharepoint/" > <MetaData> <ContentTypes> <ContentTypeRefID="0x01001ABBAD4652DE4CCEAB3C270F1DFD5F86"> <FolderTargetName="TechEd List" /> </ContentTypeRef> <ContentTypeRefID="0x0120" /> </ContentTypes> <Fields> <FieldID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}"Name="LinkTitle"DisplayName="Quote Text"Sealed="TRUE"Required="TRUE"/> <FieldID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}"Name="LinkTitleNoMenu"DisplayName="Quote Text"Sealed="TRUE"Required="TRUE"/> <FieldID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"Name="Title"DisplayName="Quote Text"Sealed="TRUE"Required="TRUE"/> <FieldID="{BABE2FC9-19C5-4310-8DE2-2C365770EE62}"Name="QuoteAuthor"DisplayName="Author Name"Type="Text"MaxLength="64"Hidden="False"Required="True" /> <FieldID="{F005C9BF-D147-428b-AAEA-9D343CBB39F0}"Name="DateUsed"DisplayName="Date Last Used"Type="DateTime"Hidden="False"Required="False" /> </Fields> <Views> <ViewBaseViewID="0"Type="HTML"Name="TechEd View"DisplayName="TechEd View"DefaultViewForContentType="True"List="TechEd/TechEdList"> ... </View> </Views> <Forms> <FormType="DisplayForm"Url="DispForm.aspx"SetupPath="pages\form.aspx"WebPartZoneID="Main" /> <FormType="EditForm"Url="EditForm.aspx"SetupPath="pages\form.aspx"WebPartZoneID="Main" /> <FormType="NewForm"Url="NewForm.aspx"SetupPath="pages\form.aspx"WebPartZoneID="Main" /> </Forms> </MetaData> </List>
List Instance <?xmlversion="1.0"encoding="utf-8" ?> <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Id="20007" FeatureId="68C88F67-CF32-4474-8F42-9C89D8465395" Title="TechEd Lookup List" Description="Lookup list used to say how great TechEd is" Url="Lists/TechEdLookup"> TemplateType="10001“ OnQuickLaunch="False" <Data> <Rows> <Row> <FieldName="Title">Fantastic</Field> </Row> <Row> <FieldName="Title">Brilliant</Field> </Row> </Rows> </Data> </ListInstance> </Elements> List Template Type
List Feature demo
Feature Events • Provides the ability to execute Code • Assembly must be deployed before the Feature is activated • “Clean up” on Feature Deactivation • Leave no residue! • Watch for Reactivation Bugs!!! • (You would be amazed)
Event Receiver using System; usingMicrosoft.SharePoint; namespaceTechEd.SharePoint { publicclassTechEdFeatureReceiver : Microsoft.SharePoint.SPFeatureReceiver { publicoverridevoidFeatureActivated(SPFeatureReceiverProperties properties) { } publicoverridevoidFeatureDeactivating(SPFeatureReceiverProperties properties) { } publicoverridevoidFeatureInstalled(SPFeatureReceiverProperties properties) { } publicoverridevoidFeatureUninstalling(SPFeatureReceiverProperties properties) { } publicoverridevoidFeatureUpdating(SPFeatureReceiverPropertiesproperties) { } } }
SPWebConfigModification // Create a Configuration Modification for the Compilation attribute SPWebConfigModificationconfigurationModification = newSPWebConfigModification(); configurationModification.Owner = properties.Feature.DefinitionId.ToString(); configurationModification.Sequence = 0; configurationModification.Path= "configuration/system.web/compilation"; configurationModification.Name = "debug"; configurationModification.Value = "true"; configurationModification.Type= SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute; currentWebApplication.WebConfigModifications.Add(configurationModification); // Save web.config changes currentWebApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); // Commit the changes made currentWebApplication.Update();
Feature Dependencies Feature A Feature B Feature D Deactivate Activate Feature C
Feature.xml <?xmlversion="1.0"encoding="utf-8" ?> <Feature Id="895DC494-CA68-413A-81D7-4A302EC3E355" Title="Code Camp Customisations" ... > <ActivationDependencies> <ActivationDependency FeatureId="F881EFC3-CA4C-42d3-9A06-DF31E82B6012"/> </ActivationDependencies> <ElementManifests> ... </ElementManifests> </Feature>
Feature Stapling Site Template Create Site FeatureStaple FeatureStaplee
Feature.xml <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <FeatureSiteTemplateAssociation Id="541F5F57-C847-4e16-B59A-B31E90E6F9EA" TemplateName="STS#0"> </FeatureSiteTemplateAssociation> </Elements> Feature Site Definition
Upgrading Solutions Upgrade Solution .wsp (v2) SP Admin .wsp (v2) .wsp (v1) Config DB
Structuring Solutions WSP 1 “Core” Features WSP “Core” Features WSP 2 “Visual” Features “Visual” Features Workflow Features WSP 3 Workflow Features
Solution Dependencies • Ensures a dependent solution is avalable and deployed • Does not deploy dependent solutions • Dependency check at deployment time • No VS 2010 Designer support
Upgrading Features • AddContentTypeField • Adds an existing field to a Content Type • Option to push to List Content Types • MapFile • Changes unghosted file paths in the database • ApplyElementManifest • Adds elements as part of the upgrade • CustomUpgradeAction • Specify Receiver Class – Defaults to Feature Assembly • Optional Parameters
Upgrading Features Feature Element files Element files Feature v1 Element files Element files Feature v2 XML Feature Receiver To modify existing sites To modify creation of new sites Upgrade Action
When are Features Upgraded? • Sandbox • Solution must have a different name! • Farm Wide • psconfig.exe -cmd upgrade -inplace b2b • Object Model • Feature.Upgrade()
Upgrading Solutions demo
In Conclusion • Solutions and Features are COOL • Deployment should be a Design Goal • Upgrading should be a Design Goal .wsp .wsp Customisations Install Web Farm
Thanks to our sponsorsand partners! Sponsor Premier Partners Associated Partners Supporting Partners