CodeFluent Entities: SharePoint Web Part Producer
To generate web parts, add the SharePoint Web Part Producer to your project by clicking “Add new producer” on the “Producers” folder in Visual Studio’s Solution Explorer, expand the Web Producers node and select it:
The SharePoint Web Part producer provides two main types of features:
- code generation features,
- deployment features.
You can use it to generate code, compile it and deploy it on a SharePoint server in the same run, however here since we want to be able to view and extend the code, compile with Visual Studio and deploy ourselves, we’re going to disable those deployment features.
Here’s a sample configuration:
Properties I changed are in bold:
- Source Production > Target Directory (mandatory): I’m making it point to my class library project containing my generated .NET classes
- Deployment > Copy Binaries: Set it to false, we’ll compile with VS so the producer has no binary to deploy yet,
- Deployment > Update [trust].config: Set it to false, same as before, for now we’re developing, we’re not bothering with deployment stuff,
- Deployment > Update web.config: Set it to false, same as [trust].config,
- Site Creator > Produce MsBuild Task Files: The site creator feature is to create a document library on the SharePoint server to test our generated web parts, set it to false for now,
- Site Creator > Produce Source Files: set it to false as well.
Build your project over and….ooops! We get the following error:
CF5519: The SharePoint WebParts producer needs the ‘SoftFluent.AssociationManage’ pattern to be included in the project.
Correct, the AssociationManage Aspect is needed by the SharePoint producer as it adds many-to-many management features which are required in the generated UI.
While we’re at it, I’d also recommend you add the AutoFormattable aspect to your project as in the generated UI, for one to many relations, you’ll get a preview of related data if any instead of just the number of related items.
Generate over, and there you go: you’ll see that custom web parts were generated: