More intelligent Context Menus in Visual Studio 2008 Database Projects
I'm using a SQL Server 2008 Database Project, and I'm finding it's very cumbersome to add certain items. For example, if I right click on Tables => Keys and navigate to the Add item, I'd expect to see the different kinds of keys that I can add. Instead, I see the stock items that don't apply, and I'm forced to navigate the Add New Item screen to find Primary Key.
Is there a way to make this 开发者_开发知识库more efficient? I have Resharper; can I leverage templates somehow (kind of a noob with these). Thanks!
Upgrading to VS 2010 will solve your problem. Selecting Table... from the new context menu:
yields the following selections, which are much more helpful than the 2008 versions:
Here's a suggestion:
Create a database item template. Store it in the Database Project Items subfolder of the VS folder in Program Files.
Create a macro that creates an item from that template. You can start by recording yourself adding an item, and modify the resulting macro.
Using the Tools/Customize menu, Toolbars tab, click the checkbox by the Context menu option in the left-hand list box. This will make the context menus appear in the menu bar. Locate the one you want. From what you've said this will probably be Other Context Menus/DB Project Folder.
Still on the Tools/Customize menu, switch to the Commands tab. Click on the Macros entry in the left-hand list box. Your macro should appear somewhere in that listbox.
Drag the entry for your macro onto the Context Menu drop-down menus that now appear in your menu bar. They will open up as you hover. Drop the entry onto the menu you want to enhance.
You will probably want to change the name of your new menu option. You can do this by going back to that menu from the Context Menus toolbar, until you reach your new menu option. Right click on it and you will be able to rename it or assign it an icon.
Close the Tools/Customize menu. You will now have a new menu option on your context menu!
Now, the macro you recorded? You'll probably have to fiddle with it A LOT to get it to work properly from its new context. Macro programming (and VS extensibility) is like that.
If you want to make your menus context-sensitive, so that certain content only appears when certain conditions are true (like the folder you're clicking on being named "Tables") you will probably need to write an add-in. This can be both fun and a time sink, but in the end you'll know a lot more about how VS works and have your menus behaving exactly as you want.
精彩评论