In this post we will describe how to use Visual Studio 2013 to create the custom master page in SharePoint 2013. Here, I’m using Visual Studio 2013 and SharePoint 2013 on premise for this scenario.
Then right click on the project, then add new item. Then in the Add New Item dialog box, select Module as shown in the fig. Give a name and click on OK as shown in below:
Then give a meaningful name to the feature, in my case I have given the name as “ActivateCustomMasterPage”. Then open the feature and give a title and select the scope as Site as shown in below
We will add an event receiver which will set our master page when feature got activated and will set to seattle master page when feature get deactivated. Right click on Feature then click on “Add Event Receiver” as shown in below:
Write the below code in the FeatureDeactivating event:
Right click on the solution explorer and then Build solution. If build succeeded then Right click and then Deploy solution. Once the solution got deployed successfully in the site collection, you can go the site collection features to see our feature must be activated. Go to site settings page, then click on “Site collection features” which is under “Site Collection Administration”. In the Site Collection Features page, you will be able to see “Activate Custom Master Page” feature status is Active like below:
Now to verify if the custom master page is deployed to the site, go to the site settings page then click on “Master pages and page layouts” which is under “Web Designer Galleries”. Here you will be able to see master page under “Master Page Gallery” like below:
Now we can go to the settings and see if our custom master page is selected or not. Go to the site settings page, then click on Master page under Look and Feel. To see this link make sure you have publishing feature activated in the site collection. You can also check out: Enable and Disable SharePoint 2013 publishing feature using PowerShell. Here once you click on Master Page, then in the Site Master Page Settings you will be able to see our custom master page is set in the “Site Master Page” as well as “System Master Page” as shown in below:
Now to check whether our feature deactivating is working fine or now. Go to the site collection feature page and deactivate the “Activate Custom Master Page” feature. Once it is successfully deactivated, go to the Master Page link under Look and Feel and you will be able to see the Seattle master page is set in the Site master page as well as settings master page.
Over all if you will see your solution explorer, it will look like below:
Hope this will be helpful.