Building extensions for Visual Studio is a multi-step process. It's similar to making other software applications, there is the coding phase, the testing and debugging phase and the deployment phase. This video provides an overview of the steps.
- [Voiceover] Building extensions for Visual Studio is a multi-step process. It's similar to making other software applications. There is the coding phase; the testing and debugging phase; and the deployment phase. In this video, I'll provide an overview of the steps. The first step is to install the extensibility tools. They are included in the Visual Studio installer, so you are probably already set up to create extensions. I'll review how to install these components later in the chapter. Next, use the new project dialogue to create a V.S.I.X. or VSIX project.
This acronym stands for Visual Studio Installer for eXtensions. The interesting part for me is that you start with the installer project, then add the extension bits later. You'll have a Visual Studio Project. In this example, it's named CodeShovel. When you compile a project, Visual Studio creates a VSIX file in the output directory. In this example, it's the CodeShovel.vsix file. Your VSIX installer is really just a special compressed file format that contains the files to be installed and a manifest file that contains information about the tool and extension type.
Change the file extension to dot zip and you can look at the contents of the installer file with any zip tool. Your VSIX project can install several types of Visual Studio tools. The focus on this chapter is on the Visual Studio extension. It can also install project and item templates, and there are other specialized Visual Studio add-ins like analyzers, which are tools that run diagnostics on your code. Finally, there's a type of add-in known as a Managed Extensibility Framework, or MEF component, which provide ways to build dynamic componentized application systems.
MEF is one of the underlying plumbing parts that makes Visual Studio extensions work. For this chapter, I'll focus on extensions. Why you can build nearly any type of extension, there are several categories of extension item templates in Visual Studio that provide a jump start for creating certain extension types. Tool windows are the extra dockable windows you see in Visual Studio, like the property window and the solution explorer. Commands are the items you see in the menus, like File open. For Windows Forms and WPF, you can create tool box controls.
Finally, there's a set of editor enhancements, like text adornments, and margin glyphs that focus on interacting or augmenting the Visual Studio editors. Now that you have the VSIX project available, you'll add the extension components to the project. Then, you'll write the code to interact with the Visual Studio IDE. Then, you'll compile the code and verify that it builds correctly. Now you're ready to debug and test the extension, and that's where it gets interesting. You see, we create the extension in Visual Studio, but we also need to install the extension inside Visual Studio before we can use it.
Good thing the Visual Studio team figure out a way to do this without much effort. When you debug the extension, Visual Studio creates the VSIX file. Next, it launches a second instance of Visual Studio. This is known as the experimental instance and it uses a separate profile for its configuration and it stores its settings in a separate section of the Windows Registry. This way, any changes made to the experimental instance of Visual Studio by the extension are isolated from your working copy of Visual Studio.
This ensures that your extension doesn't break Visual Studio. When the experimental instance is ready, the VSIX package is installed. Now your extension is part of Visual Studio and it can interact with the IDE. Also, you can put a breakpoint in the extension's source code back in the original copy of Visual Studio and debug like any other application. Also, since extensions can target older versions of Visual Studio, you can debug in an experimental instance of other versions of Visual Studio.
The final step, when the extension is ready is to deploy the VSIX file. That can be as simple as sending a copy of the file to another developer, or putting it on a file share or web server. It can also be uploaded to the Microsoft Extension Gallery, where it can be installed by any developer from within Visual Studio.
- Installing extensions
- Using CodeMaid, Productivity Power Tools, and other Visual Studio extensions
- Adding external tools
- Creating custom item and project templates
- Building your own custom extensions
- Creating VSIX installers
- Sharing custom extensions