There's plenty of documentation online on how to configure a List Definition project to create a single list using a custom content type, but how does one go about creating a project that contains multiple content types that create several lists? If custom content types for one list are defined in its instance's Elements.xml, how would another list instance use those content types? Finally, how can I get the list definition project applied to several SharePoint sites?
As mentioned, create a project with multiple features. Here is how I typically do it:
- Feature 1 = Site Columns and Content Types (sometimes I'll separate Content Types into different features)
- Feature 2 = List Definitions (aka List Templates)
- Feature 3 = List Instances (if applicable)
- Feature 4 = "empty" feature with Activation Dependencies on the other three features, with activation dependencies specified in order.
Usually only the "empty" feature is Visible (i.e. all others are set to Visible=False). This is similar to how the TeamCollab feature (which is responsible for deploying the out-of-the-box list templates). Look at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\TeamCollab by default to see it.
I don't like having so many SharePoint Project Items all over my project, so typically, I will add a Content Type SPI called "Content Types". Then as I add other Content Types, I'll design them and move them over into the Elements.xml file of the original "Content Types" SPI (so that all the Content Types are defined in a single Elements.xml file). I keep all Fields in a separate "Empty SharePoint Project Item", again in a single "Elements.xml". Because List Definitions require a special folder setup for deployment, I keep all List Definitions as separate SPI items, but just use the Feature Packaging Manager to include them all in a single feature.
I think there are exmaples of this in the Inside SharePoint 2010 book from MS Press. Here is a link to download the companion code: http://examples.oreilly.com/9780735627468-files/
I usually prefer to use one feature that deploys custom content types and an another feature to deploy list definitions. When deploying activate custom content types first and then the list definiton feature.
As long as you use same contenttypeid in your schema.xml to reference your contenttype you defined in your content type feature, it should be fine. The content type need not be defined in the same module. You can specify something like below in your schema.xml.