In this walkthrough topic, I will demonstrate you how to achieve the following things:
- Create a custom site definition.
- Specify your own master page to be used for that site.
- Create a solution file(wsp) that can be easily deployed to sharepoint.
In this artice, I will not cover how to create a master page. I will just demonstrate how you can create a feature to deploy the custom master page and apply it to a site.
If you want to know about the types of master pages, creating one yourself in detail, follow this 6 part series on Master Page.
http://sharepointmagazine.net/technical/development/introduction-to-master-pages
The main objective of this post is not how to create a master page, but how you can create your custom site definition that has custom master page and deploy into SharePoint as a solution.
I am using Visual Studio 2008 Extension for WSS 3.0 v1.3 March CTP. You can use earlier version of this tool or use other tool like WSPBuilder. You will have to know how to use the tool.
Since I will not be creating a master page, I am going to use one of the sample master pages provided by Microsoft. Download extract the master pages. I will be using the “block” sample master page.
So let’s start.
1) Create a new project of type SharePoint and use the template “Team Site Definition”.

2) The template will create the default templates that are necessary to create a team site.There is also a folder named “Site Provisioning Handler”. We will not be using this for now so you can delete this folder.

3) This is how it looks in the WSP view (View->Other windows->WSP View).

4) Inside Site Definition folder, create a folder named “MasterPage” and add the master page file “block_lay4_blue.master” which was extracted from sample master pages. I have renamed the master page file to “customsite.master”.

5) In the WSP view, make the following changes to the elementManifest.xml file. Here we specify that the master page is to be added to the master page gallery of the site.

6) Next specify the folder where the images for the custom master page will be deployed in sharepoint. Normally this will be in “12\TEMPLATE\IMAGES” folder. So we create a folder named “CustomSite” in this path and put our images there. Create a hierarchy as shown below and put there the image files. Since the master page I chose was of theme blue, I chose the images only relevant for this mater page.

7) Similarly create a folder named “CustomSite” inside the “TEMPLATE\LAYOUTS\STYLES” directory. This folder will contain the styles used by the master page.

8) Now since we have defined the place for images and the styles, let’s modify the master page to reference the necessary images and css file t the new location. Open the customsite.master page file and do the following:
a. Update the reference for css files to the reference from layouts folder. Make the following change.
Original

Modified

b. Search for the text below and update it
- src=”../../images/questionMark.gif” to src=”/_layouts/images/CustomSite/questionMark.gif”
c. Now look for any references that need to be updated in the css files. Open the file “color_layout4_blue.css” and update the following image references.
- “../images/lay4_blue_logo.gif”) to “/_layouts/images/CustomSite/lay4_blue_logo.gif”
- “../images/lay4_blue_hover.gif” to “/_layouts/images/CustomSite/lay4_blue_hover.gif”
- “../images/lay4_blue_nav_bg.gif” to “/_layouts/images/CustomSite/lay4_blue_nav_bg.gif”
d. Open the file template_layout4.css and make the following change.
- “../images/lay4_stock.jpg” to “/_layouts/images/CustomSite/lay4_stock.jpg”
9) Till now we have create a site definition feature, add a custom master page with its necessary image and css files and updated the references according to the deployment of the files. Now we need to specify in the site definition the master page to use for the site.
10) Open the Onet.xml file and look for the “Configurations” node in the xml file.

You will see that there is a Configuration with ID=0 and name “Default”.
11) Add the following attributes to the Configuration node.
Here we specified that the site with configuration ”0” would use the master page customsite.master The master page will be present in master page gallery. Step 5.
12) Expand the WebFeatures node and add an entry for the master page feature within this section. To get the ID, go to the WSP view, open the feature.xml file and copy the id of the feature.


13) With this, build and deploy the project. Go to project->properties->Debug and specify the url of a site in the “Start browser with URL” section. Build and deploy the project.

14) After deployed successfully, create a new subsite. Select the Deployment category and select the customsite template.
15) See that the newly created site is aplied with the custom master page that we specified.

Go to the master page gallery in the site collection and see that the master page “customsite.master” has been added to the gallery.
Go to the Operaitons->Solution Management section in the central admin web site to see the solution installed.

Enjoy !!!