Create a Visual Studio addin

Source: Internet
Author: User

The following two conditions are described as follows:

    1. Store the created addin in the my documents Documents \ Visual Studio 2008 \ addins directory.
    2. Store the created addin in a custom folder.

First, create an addin project named addin1:


OK, a wizard is displayed, such as naming and adding a description for this addin. The following figure describes the addin loading methods. For example, select the first one,


Next, the Addin is created.

Now we see a connect. CS file. The logic we want to add is added to this file. Find the onconnection method:

// Add a command to the commands collection:

command command = commands. addnamedcommand2 (_ addininstance, "addin1" , " addin1 ", " executes the command for addin1 ", true , 59, ref contextguids, ( int ) vscommandstatus . vscommandstatussupported + ( int ) vscommandstatus . vscommandstatusenabled, ( int ) vscommandstyle . vscommandstylepictandtext, vscommandcontroltype . vscommandcontroltypebutton);

Note that parameter 59 points to a default addin smiley icon defined by the system.

The second and third parameters here are the addin name and the content to be displayed in the Tools menu. We will change it to what we want, for example, to testaddin1, the menu content is changed to testaddin1, that is,:

CommandCommand = commands. addnamedcommand2 (_ addininstance,"Testaddin1","Testaddin1","Executes the command...

Find the exec method and add the logic to be executed. For exampleCode

If(Commandname ="Addin1.connect. addin1")

{

Handled =True;

Return;

}

Changed:

If(Commandname ="Addin1.connect. testaddin1")

{


TextselectionSelectedtext = _ applicationobject. activedocument. SelectionAs
Textselection;

Selectedtext. Text ="This is a addin test";

Handled =True;

Return;

}

The operation completed by this Addin is to insert the above string.

Note that the generated solution is as follows:


Note that there are two. addin file, where for testing. the addin path is \ My Documents \ Visual Studio 2008 \ addins \ addin1-for testing. addin, which is a configuration file automatically generated by Visual Studio to debug this addin and put it in this special folder, because Visual Studio automatically loads all addins in this folder, the file has the following configuration information:

<Assembly>C: \ Documents ents and Settings \ xiongy. Corp \ My Documents ents \ Visual Studio 2008 \ projects \ addin1 \ addin1 \ bin \ addin1.dll</Assembly>

(Note that the name of the compiled DLL is project. DLL by default. Change it to addin1.dll)

So the DLL of this plug-in will be called. Because this file is used for testing, we will delete for testing. addin to keep addin1.addin during the actual setup plug-in.

Next, add an installation project for this addin so that it can be easily installed to another user's computer. For this installation project, name it addin1setup, right-click the installation project, select view \ file system. Here, we need to select the location where the installation file is stored. Choose application folder and press F4 to view the properties,


Here, defaultlocation specifies the storage path of the installation file. The following two methods are described at the beginning of this article.

  1. Store the created addin in the my documents Documents \ Visual Studio 2008 \ addins directory.

    Change defaultlocation to [personalfolder] \ Visual Studio 2008 \ addins. Because my Documents \ Visual Studio 2008 \ addins is a large directory, it may store a lot of addin. To make the directory structure of multiple addin clearer, create a sub-folder under application folder named addin1, right-click addin1, and add project output first (select primary output in the pop-up options ), then select Add file (in the displayed dialog box, select the addin1.addin file in the addin1 project ):


    The execution result is:


     

    After compilation of the installation project, run setup.exe under the debugdirectory to install the addin to the specified directory:


    Note that it is in the addin1 subfolder.

     

    Then we can use it in the newly created Visual Studio project.

    Note that the following addin manager does not need to be operated on the following dialog box after the preceding operation is complete. You will find that the created addin has already appeared in the Tools menu.

     

    If the following checkbox is selected, for example, if the first column is checked, The addin will be loaded immediately, and the second column will be loaded at startup, in this way, the sub-menu of addin will not appear in the Tools menu.


     

  2. If defaultlocation is not changed, it will be automatically installed under the \ Program Files \ company name \ product name directory,

    Because this addin directory is not known by Visual Studio by default, you need to add it to the path configuration of addin in tools \ options.

 

 

 

 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.