Page 18 - MSDN Magazine, August 2017
P. 18

VSIX Project template. Name the project VSIX- ProjectVS2012_2017. Double-click the source. extension.vsixmanifest file to open its custom editor. In the Metadata tab, set the product name, author, version and so on. In the Install Targets tab, click the Edit button, select the Microsoft. VisualStudio.Pro identifier (that value also tar- gets the Community edition, which is basically a Professional edition) and set the target instal- lation range, [11.0,15.0], as shown in Figure 5. A square bracket means the value is included. A parenthesis would mean that the value is excluded, so you can also set [11.0,16.0). You can also target a minor version (like 15.3) using the build number (such as 15.0.26208.1).
In the Dependencies tab, delete all items. In the Prerequisites tab, click the Edit button and set the minimal Visual Studio 2017 component your extension requires. In this example, only the Visual Studio core editor is required. This section is new for Visual Studio 2017 and the version 3 manifest, so it only applies to version 15.0 (see Figure 6):
Figure 5 Installation Targets
Add a package to the VSIX project by
right-clicking the VSIX project node in Solution Explorer, then select the Add | New Item menu to bring up the Add New Item dia- log. Now, go to the Visual Studio C# Items | Extensibility | VSPackage node, select the Visual Studio Package template and name it MyPack- age.cs. Add a command to the package repeating the actions of the previous step, but selecting this time the Custom Command template. Name this MyCommand1.cs.
To follow the principle of using the fewest dependencies required, in the source code of MyPackage.cs and MyCommand1.cs, remove the unused (grayed) namespaces. Then right-click the VSIX project node in Solution Explorer and click the Manage NuGet Packages for Solution entry. In the Installed section, uninstall all the pack- ages in the order shown here:
Figure 6 Prerequisites
Microsoft.VisualStudio.Shell.15.0 Microsoft.VisualStudio.Shell.Framework Microsoft.VisualStudio.CoreUtility Microsoft.VisualStudio.Imaging Microsoft.VisualStudio.Shell.Interop.12.0 Microsoft.VisualStudio.Shell.Interop.11.0 Microsoft.VisualStudio.Shell.Interop.10.0 Microsoft.VisualStudio.Threading Microsoft.VisualStudio.Shell.Interop.9.0 Microsoft.VisualStudio.Shell.Interop.8.0 Microsoft.VisualStudio.TextManager.Interop.8.0 Microsoft.VisualStudio.Shell.Interop Microsoft.VisualStudio.TextManager.Interop Microsoft.VisualStudio.Validation Microsoft.VisualStudio.Utilities Microsoft.VisualStudio.OLE.Interop
(Don’t uninstall the Microsoft.VSSDK.BuildTools package, which is the Visual Studio SDK.)
In the project’s References node in Solution Explorer, uninstall all the remaining references (that weren’t acquired as NuGet pack- ages) except System and System.Design. Now you can rebuild the solution. You’ll get compilation errors that will be solved adding just the references shown in Figure 7.
Unfortunately, Microsoft doesn’t provide an official NuGet package for Microsoft.VisualStudio.Shell.11.0 (you can find an unofficial NuGet VSSDK.Shell.11 package, though). If you have Visual Studio 2012 installed (you should if that’s the minimal- supported version for your extension), you can get it from the GAC as explained earlier. Alternatively, you can get all the required assemblies by installing the Visual Studio 2012 SDK (bit.ly/2rnGsfq) that provides them in the subfolders v2.0 and v4.0 of the folder C:\\\\Program Files (x86)\\\\Microsoft Visual Studio 11.0\\\\VSSDK\\\\ VisualStudioIntegration\\\\Common\\\\Assemblies. The last column of the table shows the subfolder of the Visual Studio 2012 SDK where you can find each assembly.
To avoid dependencies on unofficial NuGet packages or on specific local folders (either from a Visual Studio SDK or from a
Figure 7 Visual Studio 2012 References
Assembly Name
Assembly Version
Visual Studio 2012 SDK Subfolder
Microsoft.VisualStudio.OLE.Interop
7.1.40304.0
v2.0
Microsoft.VisualStudio.Shell.Interop
7.1.40304.0
v2.0
Microsoft.VisualStudio.Shell.Interop.8.0
8.0.0.0
v2.0
Microsoft.VisualStudio.Shell.Interop.9.0
9.0.0.0
v2.0
Microsoft.VisualStudio.Shell.Interop.10.0
10.0.0.0
v2.0
Microsoft.VisualStudio.Shell.Immutable.10.0
10.0.0.0
v4.0
Microsoft.VisualStudio.Shell.11.0
11.0.0.0
v4.0
14 msdn magazine
Visual Studio




























































   16   17   18   19   20