Creating Visual Studio for Mac Extensions: A Complete Guide
By: Rajeshwari Pandinagarajan
Tags: Productivity, Mac, Csharp, Visual Studio, Extension

Extensions are an indispensable part of project development. They play a vital role in improving developer productivity by providing customization, easing development, and much more.

Visual Studio for Mac extensions are add-ons that enhance productivity and allow you to customize your project by adding new features or integrating existing tools into it. These extensions can customize both existing and new projects by adding files, new dialogs, menus, commands, and so on.

This blog post explains the procedure to create extensions for Visual Studio for Mac that can be configured to create a Visual Studio for Mac project template and extensions menu.

Prerequisites

Create IDE Extension project using AddinMaker

Open Visual Studio for Mac. To install the AddinMaker extension package, from the Visual Studio menu, Choose Extensions….

3. In the Extension Manger window, navigate to the Gallery tab and type Addin Maker into the top-right search bar. Select Addin Maker from the Addin Development category and click Install.

4. Now, AddinMaker is installed, and you can start building your own extension project. Let’s start by creating a new solution.

5. From the new project creation dialog, choose Other > IDE Extensions > General > IDE Extension > C# and click Next.

6. Name the project, choose the destination path of the project, and click Create. Visual Studio for Mac will populate the created project. Here we are going to create a Xamarin IDE extension project.

Update the extension details

Create the extension project template configuration file by right-clicking on the project and choosing Add > New File > File Template and name the file. Then, click the New button. The file will be added in your project.

2.The created template configuration file will be added as {GivenFileName.xft.xml}. Now, change the file extension type as xpt.xml from xft.xml {GivenFileName.xpt.xml}.

3. In the template configuration file, update the name, category, language name, default file name, icon, description, and parameter details within the tag in the template configuration section.Refer to the following code.

<TemplateConfiguration>

<_Name>Name of the Template</_Name>

<Category>Category</Category>

<LanguageName>Language Name</LanguageName>

<DefaultFileName>Default File Name</DefaultFileName>

<Icon>Icon of the template </Icon>

<Image file=”image file location” />

<_Description>Description of template</_Description>

<DefaultParameters>Parameter Details</DefaultParameters> </TemplateConfiguration>

Configure the template configuration file

Now, configure the template configuration file in the Manifest.addin.xml file as seen in the following screenshot.

Configure the project and add files in the template configuration file

Configure the project section in the template configuration file as shown in the following screenshot.

Here, ${ProjectName} was replaced by the name mentioned in the project creation dialog. Add the reference by using the Reference tag. If you want to refer to an assembly, then provide the type as GAC. If you are referring to another project, then give the type as project and mention the project name in the refto attribute. To add the file in the directory, add the file tag between the directory tags. If you want to add the file in the project directory, add the file tag between the File tags.

Include the template files in the extension addin

Now, include the file path in the Import tag between the Runtime tags in the ManiFestaddin.xml file, as seen in the following screenshot.

Customize the project template from the extension menu

You can customize the project template from the extension menu. To do so, follow these steps:

Add a new class file and make the following content in the file content. In the Run method, provide the Name that you mentioned in the template configuration XML file in the bracket.Refer to the following screenshot.

3. Call the above command from Manifestaddin.xml. You should mention the command id({Namespace}.{CommandID}.{Command}) in the command item id. Here, we have named it as MyXamarinProjectTemplate.MyXamarinCommands.CreateNewProject.

Change MacExtensions’ name and version

Change the MacExtensions name and version details after creating the entire project in the AddinInfo.cs file. Please refer to the following screenshot.

Install the extension

You can find the extension in the output location with the extension name *.mpack, like the following screenshot.

2. Click on the Visual Studio menu and select Extensions….

3. The Extension Manager window will open. Click the Install from file… button.

4. The Install Extension Package dialog will open. Navigate to your Mac extensions file (.mpack) location and click open to install. The extensions will be installed into your project.Refer to the following screenshot.

Run the extensions

Run the sample extension in the Visual Studio Mac instance. This will open another Visual Studio for Mac instance that will show the template in the project template wizard and Visual Studio menu.

Project template wizard

In the new instance of Visual Studio 2019 for Mac, click on the New button.

Then, in the project template wizard, you can find the template My Xamarin Project Template under Multiplatform > App.

Visual Studio for Mac menu

You can also find the given menu name (which is mentioned in the ItemSet ID tag in Manifestaddin.xml file) in the Visual Studio menu.

Source of this sample extension

You can download the complete source code for this sample extension from https://www.syncfusion.com/downloads/support/directtrac/general/ze/MacExtensions266839071.

Conclusion

I hope this article was useful in showing every step in creating extensions for a project template in the Visual Studio for Mac project template wizard and extension menu.

Syncfusion has about 1,600 components and frameworks for WinForms, WPF, WinUI(Preview), ASP.NET ( Web Forms, MVC, Core), UWP, Xamarin, Flutter, JavaScript, Angular, Blazor, Vue, 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 forum, Direct-Trac, or feedback portal. As always, we are happy to assist you!

If you like this post, we think you would also like the following articles too: