Development in Visual Studio

Source: Internet
Author: User

Visual Studio is a basic and complete set of development tools developed by Microsoft Corporation in the United States that includes most of the tools needed throughout the software lifecycle, such as UML tools, code control tools, integrated development environment (IDE), etc. And the target code is written for all platforms supported by Microsoft. It can be said that the. NET developer is inseparable from it, it can greatly improve the efficiency of writing software. As a world-class development tool, Visual Studio certainly supports the extension of its functionality through plug-ins, and developers can customize their plugins to further enhance the functionality of Visual Studio.

1 What is the add in?

The so-called add-in is a DLL dynamic-link library that is loaded into memory by Visual Studio and can provide specific functionality to the user. For general development scenarios, the most common use of add-in is to pass. NET language access to the DTE2 object. DTE2 is the top-level object of the Visual Studio Automation model, which has a set of interfaces and objects that can interact with Visual Studio. DTE2 can do the following things:

    • Accessing and invoking Visual Studio built-in functions and objects
    • Perform the compilation
    • Traversing projects in a solution
    • Customizing the UI in the visual Studio IDE
    • Extend Visual Studio features ...
2 Create vs Add in Project

Create a project named Myvisualstudioaddin with Visual Studio 2012 (set up according to the wizard, not described here) with the following interface:

3 Core Connect Class

Plug-in portal is the Connect class, first look at the class diagram of Connect:

    • Connect implements the constructor for the add-in object. Please place your initialization code inside this method.
    • OnConnection implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the add-in is loading.
    • OnDisconnection implements the OnDisconnection method of the IDTExtensibility2 interface. Receives a notification that the add-in is being uninstalled.
    • OnAddInsUpdate implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification when the add-in collection has changed.
    • OnStartupComplete implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.
    • OnBeginShutdown implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being uninstalled.
    • QueryStatus implements the QueryStatus method of the IDTCommandTarget interface. This method is called when the availability of the command is updated.
    • EXEC implements the Exec method of the IDTCommandTarget interface. This method is called when the command is called.
    • _applicationobject is the DTE2 instance, which is the root object of the host application.
    • _addInInstance is the current plug-in instance that represents the object of the add-in.

First define some internal objects, primarily custom commands, as follows:

 1//<summary> objects used to implement the add-in. </summary> 2//<seealso class= ' IDTExtensibility2 '/> 3 public class Connect:idtextensibility2, IDT  Commandtarget 4 {5 #region command definition In addition to Findinsolutionexplorer, the commands here are not commands based on functionality, but rather 6 private commands based on where the command appears ReadOnly string my_command_findinsolutionexplorer = "Findinsolutionexplorer"; 7 Private readonly string my_command_project = "Cmdinproject";//8 private readonly string My_command_ on Project         Solution = "cmdinsolution";//on the Solution 9 private readonly string my_command_menubar = "Cmdinmenubar";//on the menu bar 10 Private readonly string My_command_codewindow = "Cmdincodewindow";//code window each private readonly string My_command_fi Les = "cmdinfiles"; #endregion13 private Command FindCommand = null;15 private Commandbarbutt On Findcommandbarbuttonbutton = null;16 private Addinlogger logger = null;17 private DTE2 _applicationo bject;19 Private ENVDTE. AddIn _addininstance;20 ... 21}

Code to initialize the plug-in UI:

View CodeView CodeView CodeView Exec Code

Gets the path to the current IDE activation project:

 1//<summary> 2//Gets the Active Project FullPath 3//</summary> 4//  <returns></returns> 5 public string Getactiveprojectfullpath () 6 {7//returns the Name of the currently selected project in the solution. 8 Project proj = Getactiveproject (); 9 if (Proj!=null) ten {one string fullPath = proj. Properties.item ("FullPath"). Value.tostring (); return fullpath;13//return proj. fullname;14}15 return "",}18//<summary>19// Gets the Active project20//</summary>21//<returns></returns>22 public Proj             ECT Getactiveproject () @ projects = (array) _applicationobject.activesolutionprojects;25 if (projects! = NULL && projects.   Length > 0) 26 {27              return projects. GetValue (0) as project;28}29 projects = (Array) _applicationobject.solution.solutionbuild.startupp ROJECTS;30 if (projects! = NULL && projects. Length >= 1) (projects).             GetValue (0) as project;33}34 projects = (Array) _applicationobject.solution.projects;35 if (projects! = NULL && projects. Length > 0) (Projects) GetValue (0) as project;38}39 return null;40}

You can participate in this article about how to generate C # code codes based on the database structure.

4 Plugin Release

After you have created an add-in, you must register the addition program with Visual Studio before you can activate it in the add-in manager. Do this by using an XML file that has a. addin file name extension. The. addin file describes the information that Visual Studio needs to display the add-in in the add-in manager. When Visual Studio starts, it looks for the. addin file location and gets any available. addin files. If the file is found, the XML file is read and the add-in Manager is provided with the information needed to start the add-in when it is clicked. When you use the Add-in wizard to create an add-in, a. addin file is automatically created. You can also use the information in this topic to manually create a. addin file. I am using Visual Studio2012 to copy the. addin file and the corresponding DLL to the C:\Users\wangming\Documents\Visual Studio 2012\addins file:

If the publication has no errors, after you restart visual Studio2012, right-click the popup menu on the project file to see the following interface:

A command button for a Myvs add-in is also added to the menu bar by creating a Jackwang command button and the Tools menu, such as:

5 code generator

The code generator (used here is the Yuvalsol project, which I integrate into the plug-in) can select the corresponding table based on the database selected by the user, and then generate the C # class corresponding to the table structure:

6 Plugin Uninstall

What if the plugin you have defined wants to uninstall? See https://msdn.microsoft.com/en-us/library/ms228765.aspx.

    • Delete the. addin file for the plug-in. The default path is: \users\username\my documents\visual Studio 2012\addins\ (please see the specific path according to the actual situation)

    • In the Visual Studio Developer Command line, enter Devenv/resetaddin myvisualstudioaddin.connect to uninstall (myvisualstudioaddin.connect Is the fullclassname in the Myvisualstudioaddin.addin file;

    • At this point, add-in does not appear in the IDE, and uninstallation is complete. However, to complete the removal of the plugin must manually delete the corresponding project file (if you debug again, may be registered again);

7 Summary

Through the plug-in mechanism can be easily customized vs IDE, general software companies have their own set of frameworks, its code is also a certain package, and different, you can expand Vs, through the custom code generation tool to quickly generate the code to meet the company's needs, thus from the work of repetitive machinery freed ( Although fully auto-generated code cannot be used directly, manual adjustment on this basis also increases the efficiency of code authoring and reduces the number of human error points like spelling/punctuation.

  Although we do not produce code, is the code of the porter, but the correct way to open is to use code to help us carry the code!!!

Development in Visual Studio

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.