I was finding it hard to find a specific answer on how to write a Solution Package with a Feature that would create a InfoPath Form Library with the associated template working when you click the New button.
This approach allows for the most "hands-off" governed approach. Having to publish the form manually from the InfoPath client seemed overkill and error prone. In taking this approach I also used .udcx files to manage my Data Connections on my form. This allowed me to have different Data Connection configurations in each environment I deployed this solution too.
This is how I went about this:
Deploy to InfoPath Forms Server
I created my InfoPath form and published it to the InfoPath Forms Server by going to Central Administration | Application Management | Manage Form Templates | Upload Form Template. Once it was created here, I then activated this form on the desired Site Collection. This can be done programmatically by using stsadm commands uploadformtemplate and activateformtemplate.
Create an Forms Library
I then created a Forms Library in a blank Site and turned on Content Types from the Advanced Settings. I selected 'Add from existing site content types' option in Library Settings and selected the InfoPath Form Content Type that had been activated in the previous step.
I then changed the default content type by modifying the order in 'Change new button order and default content type' option in Library Settings.
From the Library Settings page I then clicked on the default content type that was created and selected 'Delete this content type' from the List Content Type page.
To test this I went to the List AllItems.aspx page and clicked New and it opened up my InfoPath form.
Scripting this list
Now reading around, there are two main ways of doing this sensibly, one is using the Solution Generator Tool provided with vsewss extensions or using the wspbuilder. Both will provide a way of creating a schema.xml file with the relevant files (e.g. AllItems.aspx, Combine.aspx, DispForm.aspx, EditForm.aspx, MyItems.aspx, repair.aspx, template.xml, upload.aspx and webfldr.aspx).
I actually used the Solutoin Generator tool and then moved the created List and files into a new STSDEV project that I created. This gave me flexibility when developing on Redeploying the Solution Package etc. from directly within the Visual Studio IDE.
I then added some extra bits to the DeploymentFiles folder created by stsdev with awesome new SharePoint Solution Installer tool.
Building SharePoint Lists manually
The CAML code to create lists in feature files is tough! There was a helpful MSDN article on creating Fields, Content Types and deploying them. I also found this MSDN reference handy which documented the <ListTemplate> element of the elements.xml file.
Scope of Feature deployments article by Serge van den Oever is extremely useful with lots of hyperlinks off to the various areas of the MSDN reference guides.
Binding to SharePoint Lists
One downfall of the .udcx files is that if you point to SharePoint lists, it actually uses the ListId GUIDs so in each environment this is going to be different along with the Site url used. This does mean some serious modifications when deploying to a new environment. I'm sure someone will come up with a cute tool for creating these on the fly...
There doesn't appear to be much out there on creating SharePoint Lists on the FeatureActivated method. There is one article on the MSDN blogs from March last year which goes into creating new columns on a List which is close enough to get my head around.
Be careful not to change the SolutionConfig.xml file SolutionName once stsdev has created it as this will actually cause the Build process to break as this ties into where it should find particular files. The error I was getting was this: 'The system cannot find the file specified'. Fortunately I was changing these things incrementally and caught that this had broken the build ;-)
Some home truths about the SharePoint Solution Generator
Sezai pointed me in the general direction of this article on the drawbacks of using this tool. Sezai also pointed me to this stsadm extension from Waldek Mastykarz that has the same functionality at the command line. This was basically written because the SharePoint Solution Generator (SSG) doesn't work in Visual Studio 2008. I must admit this seemed to create the same Schema.xml as the SSG did.
Teething problems with Feature Deployment
As a side note I did have some issues and the logs were awesome at debugging this ...was quietly surprised!
#20001: Cannot open file "schema.xml" for reading.
(#3: Cannot open file "schema.xml" for reading.)
Failed to retrieve the list schema for feature a26fdbe7-7835-4d8f-b3cb-761cbc830ccd, list template 10001; expected to find it at: "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Features\InvoiceTracking\InvoiceList".
Failed to find the list schema for FeatureId 'a26fdbe7-7835-4d8f-b3cb-761cbc830ccd', list template ID 10001. Cannot create list in web "http://scoltsp/jeremy" at URL "(null)".
Unknown SPRequest error occurred. More information: 0x81070201
So basically my hunch about it assuming where the schema.xml file was correct, and the project has placed the Schema.xml file in my .wsp file, but when the feature deploys it doesn't copy the schema.xml file into the feature folder! Turns out the <ElementFile> element is required here under the <ElementManifests> element in the feature.xml file (ref: MSDN Feature.xml Files).
Teething problems with creating the SharePoint List from ListInstance
I had some issues with declaring a ListInstance object, this useful article gives a list of TemplateIds to use and notes that you need to define the FeatureId also for it to work.
Description ="This library will store the Invoices for tracking purposes."