How To Plan the Deployment of Farm Solutions for SharePoint 2013 ?
While everyone is talking about Apps, there are still significant investments in Full Trust Solutions and I am sure that many OnPrem deployments will want to carry these forward when upgrading to SharePoint 2013. The new SharePoint 2013 upgrade model allows Sites to continue to run in 2010 mode after upgrading and each Site Collection explicitly has to be upgraded individually.
Not the way it worked in 2010 with Visual Upgrade, but this time there is actually both a 14 and 15 Root folder deployed and all the Features and Layout files from SharePoint 2010 are deployed as part of the 2013 installation.
For those of you new to SharePoint, the root folder is where SharePoint keeps most of its application files and the default location for this is “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\[SharePoint Internal Version]”, where the versions for the last releases have been 60 (6.0), 12, 14, and now 15. The location is also known as “The xx hive.”
This is great in an upgrade scenario, where you may want to do a platform upgrade first or only want to share the new features of 2013 with a few users while maintaining an unchanged experience for the rest of the organization. This also gives us the opportunity to have different functionality and features for sites running in 2010 and 2013 mode. However, this requires some extra thought in the development and deployment process that I will give an introduction to here. Because you can now have Sites running in both 2010 and 2013 mode, SharePoint 2013 introduces a new concept of a Compatibility Level. Right now it can only be 14 or 15, but you can imagine that there is room for growth. This Compatibility Level is available at Site Collection and Site (web) level and can be used in code constructs and PowerShell commands.
I will start by explaining how you use it while building and deploying wsp-files for SharePoint 2013 and then finish off with a few things to watch out for and some code tips.
If you take your wsp-files from SharePoint 2010 and just deploy these with Add-SPSolution -> Install-SPSolution as you did in 2010, then SharePoint will assume it is a 2010 solution or a “14” mode solution. If the level is not specified in the PowerShell command, it determines the level based on the value of the SharePointProductVersion attribute in the Solution manifest file of the wsp-package. The value can currently be 15.0 or 14.0. If this attribute is missing, it will assume 14.0 (SharePoint 2010) and since this attribute did not exist in 2010, only very well informed people will have this included in existing packages.
For PowerShell cmdlets related to installing solutions and features, there is a new parameter called CompatibilityLevel. This can override the settings of the package itself and can assume the following values: 14, 15, New, Old, All and “14,15” (the latter currently also means All).
The parameter is available for Install-SPSolution, Uninstall-SPSolution, Install-SPFeature and Uninstall-SPFeature. There is no way to specify “All” versions in the package itself – only the intended target – and therefore these parameters need to be specified if you want to deploy to both targets.
It is important to note that Compatibility Level impacts only files deployed to the Templates folder in the 14/15 Root folder.
That is: Features, Layouts-files, Images, ControlTemplates, etc.
This means that files outside of this folder (e.g. a WCF Service deployed to the ISAPI folder) will be deployed to the 15/ISAPI no matter what level is set in the manifest or PowerShell. Files such as Assemblies in GAC/Bin and certain resource files will also be deployed to the same location regardless of the Compatibility Level.
It is possible to install the same solution in both 14 and 15 mode, but only if it is done in the same command – specifying Compatibility Level as either “All” or “14,15”. If it is first deployed with 14 and then with 15, it will throw an exception. It can be installed with the –Force parameter, but this is not recommended as it could hide other errors and lead to an unknown state for the system.
The following three diagrams illustrate where files go depending on parameters and attributes set (click on the individual images for a larger view). Thanks to the Ignite Team for creating these. I did some small changes from the originals to emphasize a few points.
When retracting the solutions, there is also an option to specify Compatibility Level. If you do not specify this, it will retract all – both 14 and 15 files if installed. When deployed to both levels, you can retract one, but the really important thing to understand here is that it will not only retract the files from the version folder, but also all version neutral files – such as Assemblies, ISAPI deployed files, etc. – leaving only the files from the Root folder you did not retract.
To plan for this, my suggestion would be the following during development/deployment:
- If you want to only run sites in 2013 mode, then deploy the Solutions with CompatibilityLevel 15 or SharePointProductVersion 15.0.
- If you want to run with both 2010 and 2013 mode, and want to share features and layout files, then deploy to both (All or “14,15”).
- If you want to differentiate the files and features that are used in 2010 and 2013 mode, then the solutions should be split into two or three solutions:
- One solution (“Xxx – SP2010”), which contains the files and features to be deployed to the 14 folder for 2010 mode. including code-behind (for things like feature activation and Application pages), but excluding shared assemblies and files.
- One solution (“Xxx – SP2013”), which contains the files and features to be deployed to the 15 folder for 2013 mode, including code-behind (for things like feature activation and Application pages), but excluding shared assemblies and files.
- One solution (“Xxx – Common”), which contains shared files (e.g. common assemblies or web services). This solution would also include all WebApplication scoped features such as bin-deployed assemblies and assemblies with SafeControl entries.
- If you only want to have two solutions for various reasons, the Common solution can be joined with the SP2013 solution as this is likely to be the one you will keep the longest.
The assemblies being used as code-files for the artifacts in SP2010 and SP2013 need to have different names or at least different versions to differentiate them. Web Parts need to go in the Common package and should be shared across the versions, however the installed Web Part templates can be unique to the version mode.
Things to watch out for…
There are a few issues that are worth being aware of that may be fixed in future updates, but you’ll need to watch out for these currently. I’ve come across an issue where installing the same solution in both levels can go wrong. If you install it with level All and then uninstall it with level 14 two times, the deployment logic will think that it completely removed the solution, but the files in the 15/Templates folder will still be there.
To recover from this, you can install it with –Force in the orphan level and then uninstall it. Again, it is better to not get in this situation.
Another scenario that can get you in trouble is if you install a solution in one Compatibility Level (either through PowerShell Parameter or manifest file attribute) and then uninstall with the other level. It will then remove the common files but leave the specific 14 or 15 folder files and display the solution as fully retracted.
Unfortunately there is no public API to query which Compatibility Levels a package is deployed to. So you need to get it right the first time or as quickly as possible move to native 2013 mode and packages (this is where we all want to be anyway).
An additional tip is to look for hard coded paths in you custom code such as _layouts and _controltemplates. The SPUtility class has been updated with static methods to help you parse the current location based on the upgrade status of the Site. For example, SPUtility.ContextLayoutsFolder will give you the path to the correct layouts folder. See the reference article on SPUtility properties for more examples.
I hope this gave you an insight into some of the things you need to consider when deploying Farm Solutions for SharePoint 2013. There are lots of scenarios that are not covered here. If you find some, please share these or share your concerns and I will try to add it as comments or an additional post..