A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Previous articlesArticleIn, we just managed to gain a glimpse of vsx by creating and analyzing three very small packages generated by the vspackage wizard. These examples help us to familiarize ourselves with the basic steps for creating a small package. However, we must take a deeper look at how visual studo ide works and how it integrates package.
Before we discuss other details, we should first sort out our understanding of vsx. In this article, we will not create anyCodeTo clarify the concepts related to vsx.
Warning "the underlying layer uses com"
I have mentioned many times in the previous articles that Visual Studio's extensibility development is based on the COM technology. Objects and entities (such as commands, menus, toolbar, windows, editors, and projects) in a package are COM objects. Of course, if we use managed code (such as C # and VB. NET), we can see that these classes and instances are managed. net types and instances. But if we use unmanaged code, we have to process COM objects and instances.
During vsx code development, many modes and features can be used because vsx uses com both in and out. I suppose you do not have a deep understanding of COM (I am not a com expert myself), but I will tell you some basic knowledge that must be understood later.What is Visual Studio package?
In the previous articles, we have created several simple Visual Studio packages, so we have a preliminary understanding of vspackage. Now let's take a deeper look at it.
Vspackage is a basic unit for building Visual Studio. In fact, Visual Studio is made up of a series of vspackage collaborative work, just like an ecosystem. A package is a basic unit of Vs in terms of its architecture, deployment, security, and license authentication. In addition, one or more packages can exist physically in the sameProgramCentralized.
Developers (including Visual Studio developers) can expand vs ide by creating vspackage. These extensions can be:
In the subsequent articles, we will discuss the details of these extensions one by one. Here I will give you a basic overview to illustrate what they are and how they are used in.
In addition, a package can display its own information in the Visual Studio startup interface or in the dialog box.
A package can save its status and configuration information in a persistent storage device and read these configurations. For example, you can set syntax highlighting, Font, color, and labels in a text editor.
Each package must be signed by the so-called package load key (PLK). Visual Studio uses it to check the validity of the package. Visual Studio only loads a package with a valid PLK. In addition, technically, the package is implementedIvspackageInterface type. This time we will not discuss ivspackage in depth, but in subsequent articles we will test its details through code.What is a service )?
Generally, we do not develop a package to develop a package. We create packages because they not only provide functions for ourselves (in this case, we are consumers), but also provide functions for other packages (in this case, other packages are consumers ). For example, assume that our package provides a tool window to find reference to a specific method, and we are the consumer of this window. If this package not only provides the search function for this tool window, but also serves as a "callable method" for other package services, other packages are the consumers of this service.
Therefore, a service is a package or package and its related objects (when I say "package object, I mean the contract between windows, commands, designers, and other things created by the package itself.
Describes the concept between vspackage and service:
(Translator's note: I am very sorry, there is a picture missing here. The image link in the original text is invalid. I contacted the original text author but did not respond to it. If I find this image later, I must add it .)
Vspackage can contain services, which are called service providers. In,Vspackage1AndVspackage3Is the service provider, andVspackage2No. A Global Service (Global Service). Vspackage1 and vspackage3 both contain global services, which can be called by vspackage2 (or other packages ). A package can also contain services that can only be called by itself or can only be called by package objects. This service is called a local service (Local Service). Both vspackage1 and vspackage3 contain local services, which are called by objects (for example, by the editor in vspackage1 and the tool window in vspackage3 ).Use Service
There is a bad message about services in vsx: they are hidden and cannot be easily discovered. This means we cannot guess which services can be provided in a package (or other objects.
Therefore, if you want to use a service, you must "call it by its name", which means you must know the name of the service. The only way to know the service name is to check the documentation provided by the package where the service is located. The vsx document lists about 130 services.
Generally, a service is defined as an interface. Most services only implement one interface, but some services implement multiple interfaces. Therefore, when we want to use a service, we must know two "names": Service name and interface name.
You may have noticed that I use quotation marks for "name. This is because all services are objects. If we use the InterOP type, "names" are their. net type. If we use a COM Object (unmanaged code), the "name" is the guid of these COM types.
Let's use an example to illustrate it more clearly! InSimplecommand, We useSvsuishellService to display a message box, we useGetserviceMethod to obtainIvsuishellInterface reference:
1:Ivsuishell uishell = (ivsuishell) getservice (Typeof(Svsuishell ));
2:Uishell. showmessagebox (...);
When we get a service reference, we can use the methods and attributes it provides. In the above example, we call this service instanceUishellThe showmessagebox method.Load package and Access Service
The way vspackage accesses the Service (now I only mean getting the service instance through the getservice method) brings some "Features" and results to the service model.
After learning so much about the service, if I tell you that you must register them before using the service, I guess you will not be surprised.
To register a service, you must addProvideserviceattribute.Regpkg.exeThis attribute is used to register the service.
Although there are a lot of interesting things about services, this is enough for the moment. In the future, we will study it through code.Interoperability assembly and managed package framework
. NET developers prefer managed. Net types because they can take advantage of the powerful features of the underlying runtime environment. However, for historical reasons (vs versions earlier than the. NET era), the main part of Visual Studio is built on unmanaged code and supports COM classes and interfaces. To access COM objects,. NET provides something called interoperability Assembly. In short, it uses the. Net type to encapsulate the com type. We have two main methods to use the COM Object in vsx: Creating unmanaged code (for example, using C ++ ); or use the interoperability assembly to write managed code (using C # Or VB.. net ).
For me, I prefer to host code (and I guess most. NET developers do), so I will use the InterOP assembly for my sample code. In some common tasks, com uses different modes, such as type identification, memory allocation, and exception management. In addition, COM does not support inheritance.
If we only use the InterOP assembly, our code will become very lengthy and cannot use the language and some runtime functions provided by. NET and C. Microsoft created a framework named managed package framework (MPF) on the com interoperability assembly of Visual Studio, which can help us to create vspackage with localized hosting code.InterOP assembly in vsx
A bunch of vsx InterOP assembly is installed in GAC. You can also installC: \ Program Files \ Microsoft Visual Studio 2008 SDK) UnderVisualstudiointegration \ common \ assembliesFind them in the subdirectory. These InterOP Assemblies start with Microsoft. visualstudio, but not all assemblies starting with this are InterOP assemblies. In this folder, you can see almost 100 assembly files. The InterOP assembly is as follows (I omittedMicrosoft. visualstudioPrefix ):
|~. Shell. InterOP||
This Assembly defines hundreds of core InterOP types (including interfaces, structures, enumerations, classes, and so on)
|~. Shell. interop.8.0
~. Shell. interop.9.0
In VS 2005 and vs 2008, different COM types are defined in these two sets, of which 8.0 is used for VS 2005, 9.0 is used for vs 2008.
|~. Ole. InterOP||
This Assembly encapsulates hundreds of standard Ole types.
~. Textmanager. InterOP
Visual Studio has a good built-in editor. These two sets are used to access the Editor interface. Among them, 8.0 is for the new interface types in Visual Studio 2005 and 2008.
|~. Debugger. InterOP||
If you want to access the interfaces and debugging functions in the built-in debugger provided by vs IDE, you can use this assembly.
the MPF assembly and InterOP assembly (and other vsx-related Assembly) are in the same folder and begin with Microsoft. visualstudio . The most important assembly is as follows:
|~. Shell and ~. Shell.9.0||
these two sets define the core types of MPF. The Assembly ending with 9.0 is for vs 2008. If you use vs 2008, you should use this Assembly to register your compiled package.
|~. Shell. Design (Translator's note: ~. Shell. desing should be a clerical error.)||types defined in this set can be used to extend the Visual Studio designer.|
Assembly to be referenced in vspackage
If you use vs 2008 to create a new vspackage, The Wizard will add some references to the InterOP assembly and MPF Assembly. These references include:
If you need other InterOP or MPF assembly, you can add reference by yourself.Summary
In this article, we have discussed the basic concepts and most important details of vsx.
Of course, there are many other important concepts in vsx, but it is sufficient for us to continue our learning.
In the next article, we will continue to use code examples to explore vsx development.
Start building with 50+ products and up to 12 months usage for Elastic Compute Service