I am upgrading local community portal from SharePoint Server 2007 to SharePoint Server 2010. I also have to write deployment scripts so other guys can also use our codebase. One thing my deployment script has to do is to force correct master pages to sites. There is one little trick you should know when setting master pages for publishing webs. Here’s how I got things work.
Publishing site have two master pages – one is custom master page that is used to show site for visitors and the other is system master page that is used with site settings etc. SharePoint publishing infrastructure allows webs to inherit master page settings from parent web. If you do something like this:
then it sometimes works and sometimes it doesn’t.
How is master page inheritance defined?
SharePoint Publishing infrastructure extends SharePoint existing sites. Yes, it extends, it doesn’t replace anything. If we need to keep custom information about web we have to use web’s properties collection. Let’s see what we have there.
vti_approvallevels: Approved Rejected Pending\ Review
vti_categories: Travel Expense\ Report Business Competition Goals/Objectives Ideas Miscellaneous Waiting VIP In\ Process Planning Schedule
Okay, seems like we are on our way. Take a look at the property that I made bold. This property affects the checkbox selection on the following screenshot fragment (taken from master page settings screen).
You may set custom master to whatever you want but if you don’t change inheritance rule too then SharePoint still uses master page of parent web.
Here is my solution and that works for me. Besides setting master page for web I also set __InheritsCustomMasterUrl to False.
One thing more to mention – this is PowerShell script here. Don’t be confused! :)
As with many other things the behavior of SharePoint is unintuitive. You can find a lot of different sources from web where people suggest you to set custom master page and they don’t know that it doesn’t work without additional cool porn I just described here. Changing properties like this directly is technical design flaw in SharePoint and things like these should be done through PublishingWeb or another class one day when SharePoint API evolves.