There are cases that a custom master page need to be provisioned in Visual Studio solution to the SharePoint 2013 site. and It might be tricky to start creating master page from scratch.
Following the steps below will enable you quickly create a base master page in Visual Studio.
1. create a minimal master page
- Browse to your publishing site.
- In the upper-right corner of the page, choose Settings, and then choose Design Manager.
- In Design Manager, in the left navigation pane, choose Edit Master Pages.
- Choose Create a minimal master page.
- In the Create a Master Page dialog box, enter a name for the master page, and then choose OK. At this point, SharePoint creates both a .master file and an associated HTML file with the same name in the Master Page Gallery.In Design Manager, your HTML file now appears with Conversion successful displayed in the Status column.
- Follow the link in the Status column to preview the file.The preview page is a live server-side preview of your master page. The preview page also contains a Snippets link in the upper-right corner. This link opens the Snippet Gallery, where you can begin replacing static or mock-up controls in your design with dynamic SharePoint controls. After your master page previews successfully, you will see a <div> tag that gets added to your HTML file. You may have to scroll to the bottom of the page to see the <div> tag.This <div> is the main content block. It resides inside a content placeholder named ContentPlaceHolderMain. At run time, when a visitor browses your site and requests a page, this content placeholder gets filled with content from a page layout that contains content in a matching content region. You should position this <div> where you want your page layouts to appear on the master page.
- You can edit the HTML file that resides directly on the server by using an HTML editor to open and edit the HTML file in a mapped drive. Each time you save the HTML file, any changes are synced to the associated .master file.
2. Download the MasterPage and HTML
- Go to MasterPage Gallary
- Find your created Master Page and HTML File and “Download A Copy” the same by clicking on the right side … button
- Keep the Downloaded files to specific location
3. Integrate the master page to Visual Studio Project
- Create the module as depicted in below fig
- Add the Step II copied .MasterPage and .HTML to Module
- Edit the the Element.xml as below,
- Create a publishing feature and add the the module to it
- Deploy the Feature and activate the same
- Now Master Page should reflect to master page gallery of deployed site