Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (141).NET Core  (21)Angular  (38)ASP.NET  (47)ASP.NET Core  (52)ASP.NET MVC  (83)Azure  (26)Blazor  (42)DocIO  (18)Essential JS 2  (64)Essential Studio  (158)Flutter  (37)JavaScript  (132)Microsoft  (95)PDF  (46)React  (29)Succinctly series  (118)Syncfusion  (374)TypeScript  (30)Uno Platform  (2)UWP  (4)Vue  (25)Webinar  (12)Windows Forms  (52)WPF  (85)Xamarin  (102)XlsIO  (19)Other CategoriesBarcode  (4)BI  (29)Bold BI  (3)Build conference  (6)Business intelligence  (53)Button  (4)C#  (97)Chart  (36)Cloud  (8)Company  (445)Dashboard  (4)Data Science  (3)Data Validation  (2)DataGrid  (25)Development  (232)Doc  (7)eBook  (89)Enterprise  (22)Entity Framework  (4)Essential Tools  (14)Excel  (10)Extensions  (6)File Manager  (3)Gantt  (6)Gauge  (3)Git  (3)Grid  (24)HTML  (8)Installer  (1)Knockout  (2)LINQPad  (1)Linux  (1)M-Commerce  (1)Metro Studio  (11)Mobile  (123)Mobile MVC  (9)OLAP server  (1)Orubase  (12)Partners  (20)PDF viewer  (14)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (5)Road Map  (9)Scheduler  (13)SfDataGrid  (7)Silverlight  (21)Sneak Peek  (12)Solution Services  (2)Spreadsheet  (2)SQL  (3)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (8)Tips and Tricks  (10)UI  (51)Uncategorized  (68)Unix  (2)User interface  (39)Visual State Manager  (1)Visual Studio  (12)Visual Studio Code  (6)Web  (78)What's new  (44)Windows 8  (19)Windows App  (1)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
Creating Visual Studio Extensions Using Visual Studio 2019 - A Complete Guide

Creating Visual Studio Extensions Using Visual Studio 2019—A Complete Guide

Visual Studio extensions are add-ons that allow you to customize and enhance your project by adding new features or integrating existing tools into it. They increase your productivity. Visual Studio extensions can customize an existing or new project by adding files, new dialog, menus, commands, and so on.

Read more details about the extensions here.

This post explains the creation of Visual Studio extensions in Visual Studio 2019, that can be configured to,

  • Create a new project dialog
  • Extensions menu

Prerequisites

Create Visual Studio project template

The Visual Studio project template, when applied to an existing or a new project, adds basic code and modifies the structure of the project, expanding on the predefined project template.

You can create a project template for any project type. Here, I am going to create a new WPF project for demonstration purposes.

Create a WPF project and add the code, assembly references, folder structure, and other details that you expect to be added in a new project.

Export the project as a template using the Export Template option in the Project menu.

Select the Project template option, choose the project that you want to export as a template, and click Next.Export Template Wizard - Choosing project template

Fill in the template name and description, then click Finish.Export Template Wizard - Select Template Options

By default, the template files are saved in %userprofile%\Documents\Visual Studio 2019\My Exported Templates\{Template name}.zip.

I have named my Template MyWPFProject.

Add filter tags in vstemplate

Extract the template .zip file (MyWPFProject.zip) and open the MyTemplate.vstemplate file. Add the following tags under the TemplateData tag to display the template in the Create new project dialog of Visual Studio 2019.

<LanguageTag>C#</LanguageTag>
<PlatformTag>windows</PlatformTag>
<ProjectTypeTag>desktop</ProjectTypeTag>
<TemplateID>MyWPFTemplateApplication</TemplateID>

Note: You can add duplicate tags to enable other languages like Visual Basic in another LanguageTag. The value of the TemplateID tag will be used in the Create new project dialog.

Zip all the files again with the same name (MyWPFProject.zip).

Create VSIX project

Create a new VSIX project in Visual Studio 2019 through File->New->Project. Search for VSIX Project and click Next.Create a new project dialog

Set the project name to SampleExtension and click Create.Configure your new project

The new VSIX project is now created with asynchronous service.Solution Explorer of Vsix project

Update the extension details

The source.extension.vsixmanifest has the extension name, description, author, license, and other details. Open the vsixmanifest file to edit the extension details.

Add Visual Studio project template to VSIX project

Add the Visual Studio project template (MyWPFProject) to your VSIX project to list the template in the Create a new project dialog of Visual Studio.

To add the Visual Studio project template, open the source.extension.vsmanifest file, then select Assets, and click New. The Add New Asset dialog will appear. Provide the template details as illustrated in the following screenshot.Add New Asset Dialog to add the Visual Studio project template

Click OK to add the Visual Studio project template to the VSIX project.

Creating a custom project from menu

Creating a custom project from the Create new project dialog is one way to do it. The other way is to create one using the menu option in Visual Studio.

Create a menu in Visual Studio IDE

To create a menu, add a command file from the Solution Explorer, right-click the project, and select Add > New Item.

In the Add New Item dialog, go to Visual C# / Extensibility and select Command (or Custom Command).

Name the file Command and click Add. The Command.cs, Command.png under the Resource folder, and SampleExtensionPackage.vsct files will be created and added to the project.Command resources added to the project

Open the SampleExtensionPackage.vsct and add the following menu code inside the Commands node.

<Menus>
      <Menu guid="guidSampleExtensionPackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_FILEEDITVIEW" />
        <Strings>
          <ButtonText>Create MyWPFProject</ButtonText>
          <CommandName>C&reate MyWPFProject</CommandName>
        </Strings>
      </Menu>
</Menus>

Note: Menu guid—guidSampleExtensionPackageCmdSet

Menu id—TopLevelMenu

Update the guid and id of the parent node inside the group node with the same values of guid and id as in the menu node.

<Groups>
   <Group guid="guidSampleExtensionPackageCmdSet" id="MyMenuGroup" priority="0x0600">
       <Parent guid="guidSampleExtensionPackageCmdSet" id="TopLevelMenu"/>
   </Group>
</Groups>

Update the inner text of ButtonText tag as Create My WPF Project under the Button’s String tag.

<Button guid="guidSampleExtensionPackageCmdSet" id="CommandId" priority="0x0100" type="Button">
        <Parent guid="guidSampleExtensionPackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Create MyWPFProject</ButtonText>
        </Strings>
</Button>

Add the menu IDSymbol (TopLevelMenu) inside the GuidSymbol node with the name guidSampleExtensionPackageCmdSet.

<GuidSymbol name="guidSampleExtensionPackageCmdSet" value="{bd0977d5-b805-4fbb-9e31-fbcc5d3cb437}">
      <IDSymbol name="MyMenuGroup" value="0x1020" />
      <IDSymbol name="CommandId" value="0x0100" />
      <IDSymbol name="TopLevelMenu" value="0x1021"/>
</GuidSymbol>

Call the customized project from menu

When clicking the menu (Create MyWPFProject), call the MyWPFProject (customized) Visual Studio project template to create a new project.

In the Execute method in the Command.cs class, remove existing code to show the message box and add the following code to call the Create New Project dialog.

private void Execute(object sender, EventArgs e)
{
    ThreadHelper.ThrowIfNotOnUIThread();          
    IVsSolution vsSolution = Package.GetGlobalService(typeof(IVsSolution)) as IVsSolution;
    vsSolution.CreateNewProjectViaDlg("MyWPFTemplateApplication", "MyWPFProject", 0);
}

The MyWPFTemplateApplication is the TemplateID and MyWPFProject is the template name, which is updated in the vstemplate file at the time of exporting the project template.

Run the extension

Press F5 to run the sample extension in the Visual Studio 2019 instance. This will open the new Visual Studio experimental instance. Choose Continue without code to open the Visual Studio IDE.Choosing Continue without code in Visual Studio 2019

Now you can see the Create MyWPFProject under Extensions -> Sample Extension Menu.Creating the project using the Extensions menu

When selecting the Create MyWPFProject, the Configure your new project dialog will appear as shown in the following screenshot.Configure your new project dialog

Click Create to create the project with the changes exported to the Visual Studio template.

Install the extension

You can find the extension in the output location with the extension *.vsix.vsix file in the output folder

Install this extension in other machines by running the .vsix file. The VSIX installer dialog will open to install this extension.VSIX installer

Publish the extension to Visual Studio Marketplace

The Visual Studio extension can be published in the Visual Studio Marketplace to share this extension with the public.

Refer to this documentation to publish the extension in the Visual Studio Marketplace.

Source of this sample extension

Download the complete source of this sample extension on Direct-Trac.

Conclusion

I hope this article was useful in showing you every step in creating a Visual Studio project template, and publishing and using an extension in a Visual Studio project.

Syncfusion has about 1,000 components and frameworks for WinForms, WPF, ASP.NET (Web Forms, MVC, Core), UWP, Xamarin, FlutterJavaScriptAngularBlazorVue, and React. Use them to boost your application development speed.

If you have any questions, please let us know in the comments section. You can also contact us through our support forumDirect-Trac, or feedback portal. As always, we are happy to assist you!

Tags:

Share this post:

Share on twitter
Share on facebook
Share on linkedin

Comments (1)

Great content! Super high-quality! Keep it up! 🙂

Leave a comment

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top