Deploy and set the current site's master page

Copper Contributor

I have an existing project built as a farm solution with 2 projects. I want to start switching into the new techniques of doing it.

 

I want to deploy a master page and set is as the current site’s master page. I saw the examples on PnP but they are from 2014 and related to creating sharepoint apps. Is it still the valid solution? Does that mean I have to add an extra project in my solution just for the deployments? Is there a newer way similar to feature receivers which is fast?

 

12 Replies
You don't necessarily need to do by Apps, if you are thinking in a provisioning solution where it's not required the participation of end users, you could write it using a Console App

You can deploy/set master page using PnP PowerShell cmdlets. They work across on prem and O365.  See https://github.com/OfficeDev/PnP-PowerShell

Thank you Juan. So the console application will be using C# CSOM?

Thank you Sreeni, and what if I want to take this code and deploy it for the client. Do I need to run the scripts in powershell first?

 

For example, we will end up with 3 wsp files to deploy for the client. I want to start using the new techniques. I should in this case have 1 powershell script to deploy the wsps, and deploy the master page? 

Yes, C# and CSOM
Here you are the CSOM code to set the master page...it should also work in Office 365, but remember that it's not advisable to deploy and use custom master pages in SPO in Office 365
http://sharepoint.stackexchange.com/questions/130812/how-to-assign-masterpage-via-csom

and to do the deployment in product, I package the console application and take it to the production server? How do people handle these cases? 

You can also Deploy and Set using SharePoint Workflow if you are so inclined as well if you want.

Thanks Scott, do you have examples for that?

I can certainly send you some over.

Yes please Scott. That would be great. 

I suggest that you create a PnP XML template (where you can define where the .master is, and page properties). Then, you can use the PnP provisioning framework to Apply the template, and that will Deploy and set your master page to the site. In order to Apply the template, you can use the existing PnP PowerShell commands (as other reply suggested).
More info:
https://github.com/OfficeDev/PnP-Provisioning-Schema
http://dev.office.com/blogs/introduction-to-office-365-dev-pnp-provisioning-engine