One of the new capabilities of the new Visual Studio SharePoint development tools is support for creating Site Definitions. Using the Site Definition SharePoint Project Template you can create and test Site Definition. In order to fully benefit of the new tools there are a couple of things you have to keep in mind.
Creating new Site Definitions
Creating new Site Definitions using the Visual Studio SharePoint development tools is pretty straight forward. All you need to do is to choose Add > New Project from the menu and choose the Site Definition SharePoint Project Template.
As you have noticed, Site Definition is a Project Template not an Item Template. This means that in order to have the Site Definition SharePoint Project Item (SPI) in your project, you have to create a different kind of project. You cannot add a Site Definition SPI to other types of projects. This choice has been made on purpose. Because Site Definitions are complex and often consist of many different artifacts, it is considered a good practice to separate Site Definitions from other artifacts that could be used standalone as well.
If you happen to have created a SharePoint project of a type different than the Site Definition SharePoint Project Template and you need to add the Site Definition SPI, there is a workaround that you can use. What you have to do is to add a new Site Definition Project to your solution and move the Site Definition SPI to your project.
Testing your Site Definition
Visual Studio SharePoint development tools make testing SharePoint artifacts really easy. All you need to do is to press F5 and the tools will automatically build your solution, package it, deploy the package to the specified SharePoint Site and activate the Features.
Testing a Site Definition is a little different than testing other artifacts. When testing a Web Part for example, the Web Part is being deployed to the SharePoint Site specified in the SharePoint Project’s properties. After the deployment process has been completed, you can navigate to the URL and test your Web Part. When working with Site Definitions the situation looks a little bit different: the Site Definition is being deployed to your local farm and in the test process you will very likely create a new Site (Collection) using the newly created Site Definition. This gets challenging when working with Site Collection Site Definitions.
Visual Studio SharePoint development tools assume that there is a valid Site Collection available at the specified URL. If not, you won’t be able to create the new Site Definition:
You can work around this by pointing to a URL of an existing Site Collection. While this will allow you to create the Site Definition project, the deployment process will fail resulting in an error and the newly created Site Definition will not get deployed:
What you can do to get around this issue, is to create an empty Site Collection without selecting the template:
Using the empty Site Collection your Solution will get deployed correctly and you will be able to test your Site Definition by picking your Site Definition from the list: