Sunday, July 31, 2016

Hello World - Your First Extension to .NET Visual Studio 2015 - Open Source


Visual Studio Extension - Hello World

Sometime back  I have participated in 3 days session  called .NETUNBOXED  event where I got a chance to meet with many giants of Open Source platform, Including Microsoft's Project Manager for Open Source team. I learned a lot from them, and thought of writing small hello word program to start on this series. 

So, Let's see how to write your first extension for Visual Studio 2015.

You can use any version of visual studio to write your own extensions except Express


System Requirements 

1. Visual Studio 2015 (Community / Professional / Enterprise)
2. Visual Studio Development Kit

There are three ways to install Visual Studio Development Kit. 

A. Installing VS SDK (Visual Studio SDK) during Visual Studio Installation. 
B. Installing VS SDK after installing Visual Studio. 
C.  Installing VS SDK during project creation. ( This is what I used for my First Application)


A. Installing Visual Studio and Visual Studio Development Kit together

1. Visual Studio 2015 : Any Visual Studio version except express, can be use if available, if not, your can download free Visual Studio 2015 Community version from the following link 


Choose 'Community' 

2. Make sure you click on 'Visual Studio Extensibility tool' under 'custom tool' to install Microsoft SDK 
(Software Development Kit)

VSSDKInstall


2. Visual Studio Microsoft Development Kit : 

B. Installing Visual Studio Development Kit after Installing Visual Studio

When you already have Visual Studio installed on your system, you need only Microsoft Software Development Kit to write your own extension for Visual Studio. 

1. Click on Control Panel - Programs - Programs and Features - Visual Studio 2015 - Change -



2. You will get following screen.  From Select feature, Click on Common Tools - Visual Studio                    Extensibility tool update 1 (Same as shown in earlier step)

C. Installing VS SDK during project creation.

1. Open Visual Studio 2015 - File - New - Project 
2. From Install - Template - Choose Extensibility 


3. If you don't have VSSDK, Visual studio will prompt you to install it. 




4. You will get prompted for 'Install Missing Feature' Click on 'Install''



5. You will see a screen to update 'Visual Studio Community 2015', Click on Update. 




5. You will see a following screen as a part of smooth installation. 




6. After Few Ok's following screen will get to where you see by default - ' Visual Studio Extensibility Update 3'  is already selected for you. Click on 'Next'





 Hello World 


You are ready to write your first Hello World Extension in Visual Studio. 

1. Open Visual Studio 2015 Community. 

2. Click on File - New Project - Templates - Visual C#

3. Click on Extensibility to write your first Visual Studio Extention. 

4. Choose 'VSIX Project' it stands for  'Visual Studio Installer for Extentions' 

5. Name project ' HelloWorld' 

6. Click on 'OK'



7. Right Click on the Project - Add - User Control 


8. Go Back to Extensibility - Custom Command
9. Name it as 'HelloWorldCommand' and click on 'Add'





10. You will see following screen, which shows command is getting added to the project.



11. You can see bunch of files related to Command


12. Click on 'HelloWorldCommandPackage.vsct'

13. Add 'Hello Wrold' Between 'ButtonText'
       
     

14. Open 'HelloWorldCommand.cs'

15. In 'MenuItemCallback' event replace existing code with following snippet.

            private void MenuItemCallback(object sender, EventArgs e)
            {
                        string message = "Hello World";
                        string title = "My First Visual Studio 2015 Extention"; 

16. Build And Run

Where your extension will be ?


17. When you build and run, New Visual Studio Experiment instance will be open.

18  Click on ' Tools' and you will see your first ever Visual Studio Extention in Visual Studio 2015.



19. You Will see following screen in Visual Studio Experiment instance



20 My First Visual Studio Extension - Hello World. 




These are the steps to write your First ever Visual Studio 2015 Extension.