July 15, 2016 at 1:33 am
I recently released my extension and wanted to share what I have learned so that others can start creating extensions.
SSMS Schema Folders (https://ssmsschemafolders.codeplex.com/[/url]) is an extension for SQL Server Management Studio 2012, 2014 and 2016. It groups sql objects in Object Explorer (tables, views, etc.) into schema folders.
Using Visual Studio 2015, create a VSIX project. `Templates > Visual C# (or Visual Basic) > Extensibility > VSIX Project`
There should be the option to install the Visual Studio 2015 SDK if it is not already installed.
Next add a VSPackage. `Right click on project > Add > New Item… > Extensibility > VSPackage > Visual Studio Package`
As a sample, add a Custom Command. Same as the VSPackage above. This will add a menu item to the tools menu so that we can see SSMS loads the extension.
More details can be found at https://msdn.microsoft.com/en-us/library/bb166030.aspx
When we build the project, it will create the project .dll and .pkgdef. We can ignore everything else in there for the moment. It is possible to stop it from outputting the extra files.
Copy the project .dll and .pkgdef files into a sub folder in the SSMS extensions folder. `C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Extensions`
If you tried to run SSMS now, it will attempt to verify the extension and silently fail. We can force it to skip this by adding the registry setting below. Replace the 0's with your package guid. Make sure to keep the curly brackets.
Note this is only meant for development. When they release official support for extensions then this should no longer be required.
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\SQL Server Management Studio\13.0\Packages\{00000000-0000-0000-0000-000000000000}]
"SkipLoading"=dword:1
If you run SSMS now you should see your sample menu item.
Now the problem is that if your extension loads correctly, it will remove the registry setting. We can restore the registry setting when SSMS exits by adding the following code to the package class.
protected override int QueryClose(out bool canClose)
{
UserRegistryRoot.CreateSubKey(@"Packages\{" + PackageGuidString + "}").SetValue("SkipLoading", 1);
return base.QueryClose(out canClose);
}
This does have the downside of it not loading when running multiple instances of SSMS. You can work around this by using a timer to set the reg key shortly after the Initialize() method.
You now have an extension that will load in SSMS.
If you want your extension to work with sql related features then you are going to need to add references to some SSMS dll files. The first one to add is SqlWorkbench.Interfaces.dll located in the ManagementStudio folder. This contains a lot of interfaces that you can work with. The next one you may want to add is SqlPackageBase.dll. This contains some GUIDs that will be useful for the package ProvideAutoLoad attribute.
If you want to go deeper then you can use a tool like ILSpy or Reflector. I would start with the dll files in the Extensions\Application folder.
The above method will also work with SSMS 2012 and 2014 but you need to be aware of two things. You must reference the correct version of all the dll files and the reg key is in a slightly different location.
For the references you will need to create a separate project for each SSMS version.
For the reg key the 2012 version is in \11.0\ and 2014 in \12.0\.
If you are having trouble with your extension loading, then start SSMS with the /log parameter. It will log details to `%AppData%\Microsoft\AppEnv\14.0\ActivityLog.xml`. Search the file for your package guid to find the relevant information.
If anyone knows of some good resources for developing SSMS extensions then post it here.
July 19, 2016 at 10:33 pm
Red-gate has the Ecosystem Project, handles SSMS 2008 to 2014.
No plans for 2016 thought...
Nice work having the SSMS 2016 extensions working on your own... :smooooth:
October 18, 2016 at 5:18 am
Thanks, that help me a lot.
June 5, 2017 at 7:36 am
Any ideas to extend right click on the Object Explorer?
October 25, 2017 at 4:30 pm
This is AWESOME! it does exactly what I want!
BTW - Do you plan to move this project to Github before the great Codeplex shutdown?
April 3, 2018 at 11:51 pm
Does anyone have idea when any query get executed how I can trace that query ?
March 1, 2020 at 8:22 am
Any one know or have an example on how to implement and Item menu on the Object Explorer for SSMS V18 /19? I have been looking for a long time all I found is for previous version of SSMS
July 9, 2023 at 11:53 am
Hi, Thank you for creating and sharing your SSMS Schema Folders project. I found your project on github at https://github.com/nicholas-ross/SSMS-Schema-Folders while trying to create my own extension for SSMS and learnt a lot from studying your code. I managed to add menu items to the Object Explorer's right-click context menu. It's not pretty, but it works. Please see my project on github at https://github.com/brink-daniel/ssms-object-explorer-menu. My extension, SSMS Object Explorer Menu, allows custom menu items to be added to the Object Explorer's right-click context menu, for executing any tsql statement or script. I hope you find the code useful.
Anything can be fixed
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply