In this article I will take you through a real-world scenario.
1. You need to create a Site Definition
2. When user creates a new site from this Site Definition, a new List Instance too be created
What is the Solution?
We can have multiple solutions for this:
1. Use Feature Stapling
2. Use Event Handler
3. Use Site Definition
I would recommend the third approach as it is the shortest path.
Following are the steps involved for the solution:
1. Create SharePoint Solution Project
2. Create Site Definition
3. Create List Definition
4. Include List in Site Definition
Step 1: Create SharePoint Solution Project
Run Visual Studio 2012 & create a new SharePoint project.
Choose the Farm Solution option as shown below.
Step 2: Create Site Definition
Choose Solution > Add new item > Site Definition
Enter a name for the site definition.
Step 3: Create List Definition
Add a new item > List
Enter a name for the list instance. Choose the option custom and click the Next button of wizard.
(the custom option allows you to create new fields, view fields etc.)
Click the Finish button & in the appearing page enter some unique fields for the list.
Step 5: Include List in Site Definition
Open the onet.xml of Site Definition & Reference the list from it.
You need to use the correct Template Id & Feature Id for it.
For finding feature id, open the Features > Feature 1 > .feature file > Find the GUID against featureId
Step 5: Deploy
Build & Deploy the solution
Now you are ready to test the Site Definition.
Step 6: Test
Open the Browser > Open SharePoint site > Site Contents > New Sub site
After creating the site > Go to Site Contents & you can see the List Instance there.
This concludes our Site Definition with List Instance creation.
A good read for Site Definition vs. Site Templates
In this article we have explored a real-world scenario of Site
Definition creation with List Instance. The source code is associated
with this article.