Create Custom Features for Database Projects
You can extend existing database project types by adding your own features. For example, you can create a feature that does something every time that a database project is loaded or saved. You can also create your own database schema provider and supporting project system. However, that type of extensibility is not covered in this content.
Common Tasks | Supporting Content |
|---|---|
Learn more about the extensibility points: You can read about the design of database project extensibility. | |
Create a sample project feature: Learn the steps that are required to create a custom project feature that displays a dialog box when a database project is loaded. If you follow these walkthroughs, you will:
| |
Install a custom project feature: After you create and build a project feature, you must install it before Visual Studio will recognize it. |
Every database project file (.dbproj) contains a property named "DSP" indicating the specific DatabaseSchemaProvider that handles this project when it is opened in Visual Studio. The project system creates an extension manager by using this DSP and from that constructs all the project system contributors and project features. Each feature receives an Initialize event so that it can initialize and root itself into the project system by listening to events.
The following events are raised during project open/close and save:
Every project has one ErrorManager. Some errors are persisted to the .dbmdl file and other errors are not. This is controlled through the AddPersistedCategory class. By default these categories are persisted: ModelCategory, ValidationAtBuildCategory, and ValidationOnIdleCategory. If you add another persisted category you will have to handle the project reload and verify and manage your errors. Remember that although the project was closed, the user could have edited the .dbproj file to remove a file for which you are reporting an error. It would be very confusing to users to report an error in the project when no such file exists.
Database error objects are added to the ErrorManager in specific categories. The idea is that project features can manage the lifetime of their errors through the lifetime of their category. If you are concerned about category names conflicting with other features then use a GUID as the name. The ErrorManager defines several built-in categories including:
Create Custom Database Refactoring Types or Targets
Create and Register Additional Rules for Analyzing Database Code
Generate Specialized Test Data with a Custom Data Generator
Define Custom Conditions for Database Unit Tests
Customize Database Build and Deployment by Using Build and Deployment Contributors