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.

Step 1

Now open visual studio 2013 , then File->Then in the new project dialog box , From the templates select visual C# -> office/SharePoint->sharepoint solutions. Then from the right side select SharePoint 2013 – Empty project . Give a name and click on OK as in below .
MasterPage_1_17052016

Step 2

Then give your local site for deployment and then choose “Deploy as a farm solution” as shown in the fig below:
MasterPage_02_17052016

Step 3

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:

 

MasterPage_03_17052016

Step 4
Then delete the sample.txt from the Module folder and then past the master page which we have downloaded from the site and saved in the local drive. In my case I have given the name as “MyCustomMaster.master”. Now change the Elements.xml like below:

MasterPage_06_17052016_files_files

Step 5

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

 

MasterPage_07_17052016_files_files

 

 

Step 6

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:

 

MasterPage_08_17052016_files_files

 

Step 7

Here we need to write the code ActivateCustomMasterPageEventReceiver. Write below code in the FeatureActivated event:
MasterPage_09_17052016_files_files

Step 8

Write the below code in the FeatureDeactivating event:

MasterPage_10_17052016_files_files

 

Step 9

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:

 

MasterPage_11_17052016_files_files

 

Step 10

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:

 

MasterPage_13_17052016_files_files

 

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:

 

MasterPage_14_17052016_files_files

 

Step 11

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.

 

MasterPage_15_17052016_files_files

Over all if you will see your solution explorer, it will look like below:

MasterPage_16_17052016_files_files

 

Hope this will be helpful.