Design packages in SharePoint 2013 allow us to package our customized branding from one SharePoint site and apply it to another. Design packages can include:
_catalogs/masterpage/
When a design package is created, it will only include the preceding elements that were customized or added. It will not include the items that come by default with SharePoint. In this recipe, we will cover how to create a design package from a site that is already customized.
Follow these steps to create and export a design package:
When creating a design package, each site design customization is reviewed in the wizard steps. These design customizations include master pages, page layouts, device channels, and design files (cascading style sheets, images, JavaScript, and so on). The design customizations are then packaged in a SharePoint solution file (WSP). These SharePoint solutions are sandboxed solutions that allow the site collection administrators to upload and deploy them rather than requiring a farm administrator.
A design package may also be exported with PowerShell or with code using the server-side object model.
Follow these steps to create and export a design package using PowerShell:
Microsoft.SharePoint.dll
and Microsoft.SharePoint.Publishing.dll
assemblies into the PowerShell session.[Reflection.Assembly]::LoadFrom("C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Publishing.dll") [Reflection.Assembly]::LoadFrom("C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.dll")
Get-SPSite
Cmdlet.$site = Get-SPSite http://sharepoint/sitecollection
Export
method of Microsoft.SharePoint.Publishing.DesignPackage
.$package = [Microsoft.SharePoint.Publishing.DesignPackage]::Export($site, "My PowerShell Design", $false)
$fileName = "{0}-{1}.{2}.wsp" –f ($package.PackageName, $package.MajorVersion, $package.MinorVersion)
SPFile
object representing the design package WSP file from the RootWeb
property of the SPSite
object.fileBinary = $site.RootWeb.GetFile("/_catalogs/solutions/" + $fileName).OpenBinary()
System.IO.FileStream
to save the contents of the SPFile
object to the local filesystem.$fileStream = New-Object System.IO.FileStream("C:" + $fileName, [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::Write) $fileStream.Write($fileBinary, 0, $fileBinary.Length) $fileStream.Close()
Dispose
method to discard the SPSite
object.$site.Dispose()
Follow these steps to create and export a design package with code using the server-side object model:
using
statement.using (var site = new SPSite("http://sharepoint/sitecollection"))
using
statement.using (var web = site.RootWeb)
Export
method of Microsoft.SharePoint.Publishing.DesignPackage
.var package = DesignPackage.Export(site, "My Code Design", false);
var fileName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}.{2}.wsp", package.PackageName, package.MajorVersion, package.MinorVersion);
SPFile
object representing the design package WSP file from the RootWeb
property of the SPSite
object.var fileBinary = web.GetFile("/_catalogs/solutions" + filename).OpenBinary();
System.IO.FileStream
to save the contents of the SPFile
object to the local filesystem.var fileStream = new FileStream("C:\" + fileName, FileMode.OpenOrCreate, FileAccess.Write); fileStream.Write(fileBinary, 0, fileBinary.Length); fileStream.Close();
18.119.142.85