Deploy and set the current site's master page

%3CLINGO-SUB%20id%3D%22lingo-sub-11179%22%20slang%3D%22en-US%22%3EDeploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11179%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20an%20existing%20project%20built%20as%20a%20farm%20solution%20with%202%20projects.%20I%20want%20to%20start%20switching%20into%20the%20new%20techniques%26nbsp%3Bof%20doing%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20deploy%20a%20master%20page%20and%20set%20is%20as%20the%20current%20site%E2%80%99s%20master%20page.%20I%20saw%20the%20examples%20on%20PnP%20but%20they%20are%20from%202014%20and%20related%20to%20creating%20sharepoint%20apps.%20Is%20it%20still%20the%20valid%20solution%3F%20Does%20that%20mean%20I%20have%20to%20add%20an%20extra%20project%20in%20my%20solution%20just%20for%20the%20deployments%3F%20Is%20there%20a%20newer%20way%20similar%20to%20feature%20receivers%20which%20is%20fast%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11344%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11344%22%20slang%3D%22en-US%22%3EI%20suggest%20that%20you%20create%20a%20PnP%20XML%20template%20(where%20you%20can%20define%20where%20the%20.master%20is%2C%20and%20page%20properties).%20Then%2C%20you%20can%20use%20the%20PnP%20provisioning%20framework%20to%20Apply%20the%20template%2C%20and%20that%20will%20Deploy%20and%20set%20your%20master%20page%20to%20the%20site.%20In%20order%20to%20Apply%20the%20template%2C%20you%20can%20use%20the%20existing%20PnP%20PowerShell%20commands%20(as%20other%20reply%20suggested).%3CBR%20%2F%3EMore%20info%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-Provisioning-Schema%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-Provisioning-Schema%3C%2FA%3E%3CBR%20%2F%3E%3CA%20href%3D%22http%3A%2F%2Fdev.office.com%2Fblogs%2Fintroduction-to-office-365-dev-pnp-provisioning-engine%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fdev.office.com%2Fblogs%2Fintroduction-to-office-365-dev-pnp-provisioning-engine%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11264%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11264%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20please%20Scott.%20That%20would%20be%20great.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11225%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11225%22%20slang%3D%22en-US%22%3E%3CP%3EI%20can%20certainly%20send%20you%20some%20over.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11224%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11224%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Scott%2C%20do%20you%20have%20examples%20for%20that%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11218%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11218%22%20slang%3D%22en-US%22%3EYou%20can%20also%20Deploy%20and%20Set%20using%20SharePoint%20Workflow%20if%20you%20are%20so%20inclined%20as%20well%20if%20you%20want.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11215%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11215%22%20slang%3D%22en-US%22%3E%3CP%3Eand%20to%20do%20the%20deployment%20in%20product%2C%20I%20package%20the%20console%20application%20and%20take%20it%20to%20the%20production%20server%3F%20How%20do%20people%20handle%20these%20cases%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11203%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11203%22%20slang%3D%22en-US%22%3EHere%20you%20are%20the%20CSOM%20code%20to%20set%20the%20master%20page...it%20should%20also%20work%20in%20Office%20365%2C%20but%20remember%20that%20it's%20not%20advisable%20to%20deploy%20and%20use%20custom%20master%20pages%20in%20SPO%20in%20Office%20365%3CBR%20%2F%3E%3CA%20href%3D%22http%3A%2F%2Fsharepoint.stackexchange.com%2Fquestions%2F130812%2Fhow-to-assign-masterpage-via-csom%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fsharepoint.stackexchange.com%2Fquestions%2F130812%2Fhow-to-assign-masterpage-via-csom%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11202%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11202%22%20slang%3D%22en-US%22%3EYes%2C%20C%23%20and%20CSOM%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11200%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11200%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Sreeni%2C%20and%20what%20if%20I%20want%20to%20take%20this%20code%20and%20deploy%20it%20for%20the%20client.%20Do%20I%20need%20to%20run%20the%20scripts%20in%20powershell%20first%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20we%20will%20end%20up%20with%203%20wsp%20files%20to%20deploy%20for%20the%20client.%20I%20want%20to%20start%20using%20the%20new%20techniques.%20I%20should%20in%20this%20case%20have%201%20powershell%20script%20to%20deploy%20the%20wsps%2C%20and%20deploy%20the%20master%20page%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11199%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11199%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Juan.%20So%20the%20console%20application%20will%20be%20using%20C%23%20CSOM%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11191%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11191%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20deploy%2Fset%20master%20page%20using%20PnP%20PowerShell%20cmdlets.%20They%20work%20across%20on%20prem%20and%20O365.%26nbsp%3B%20See%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-11184%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20and%20set%20the%20current%20site's%20master%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-11184%22%20slang%3D%22en-US%22%3EYou%20don't%20necessarily%20need%20to%20do%20by%20Apps%2C%20if%20you%20are%20thinking%20in%20a%20provisioning%20solution%20where%20it's%20not%20required%20the%20participation%20of%20end%20users%2C%20you%20could%20write%20it%20using%20a%20Console%20App%3C%2FLINGO-BODY%3E
Highlighted
Occasional 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
Highlighted
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
Highlighted

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

Highlighted

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

Highlighted

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? 

Highlighted
Yes, C# and CSOM
Highlighted
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
Highlighted

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? 

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

Thanks Scott, do you have examples for that?

Highlighted

I can certainly send you some over.

Highlighted

Yes please Scott. That would be great. 

Highlighted
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