Skip to main content

Create Your Own .NET MAUI Plugins with This Template

·5 mins

Have you been thinking about building your own .NET MAUI plugin? How excited would you be if I told you that its actually not that hard? In this blog post, we are going to walk you through how to build your own .NET MAUI plugin. Yes, you read that right, your own .NET MAUI plugin - the easy way!

I also have a video about this topic, go over to my YouTube channel to watch it there.

.NET MAUI Paradigm #

If you’ve been following me, then you’re likely already familiar with the main idea behind .NET MAUI. With .NET MAUI, you’re provided with a unified API that functions as an abstraction layer on top of iOS, Android, Windows, macOS, and Tizen. This UI framework, developed on .NET and C#, aids you in building cross-platform applications across all the above-listed platforms.

Each of these platforms takes pride in a unique set of APIs, which incorporate thousands of objects, functionalities, visual elements, methods, and properties that can be utilized to develop your app on that specific platform.

However, a challenge arises when trying to encapsulate all these capabilities into a unified abstraction layer within .NET MAUI. This is because some APIs are very specific and therefore hard, or almost impossible, to capture in a cross-platform context. Moreover, just dealing with the sheer number of APIs can be a daunting task.

Contribute to the Community! #

Nevertheless, this limitation presents a golden opportunity for you. You may sometime encounter a piece of functionality that you need within your application that’s available across platforms, but is not available in the .NET MAUI APIs. One solution could be to incorporate it into your project and keep it to yourself. But where’s the fun in that?

An alternative (and much more fun) approach would be to extract this functionality into a plugin and make it accessible for others to use in their projects. This way, you’re not just solving a problem for yourself, you’re also contributing appreciated solutions to the open-source community.

A screenshot of the Plugin.Maui.Feature repository template

At the time of writing this post, I have created 4 plugins - one for the pedometer, one for screen brightness, one for accessing calendar data, and another for playing audio in your .NET MAUI applications. While creating these plugins, I decided to abstract my project setup and structuring into a simple, easy-to-use GitHub repository template.

Creation of .NET MAUI Plugins #

Ready to create your first .NET MAUI plugin? The first step would be browsing through a public repository template located on my account. The repository is conventionally named “Plugin.Maui.[feature]”, where [feature] represents whatever unique functionality you want to incorporate. You can find it here.

This repository is marked as a public template, meaning that it isn’t bound by constraints such as forking onto your account. Instead, you are able to create an independent copy under your own account, clone it as a typical repository, and start working on your plugin in your way.

*** NOTE: *** I (the original creator of this template) do not keep track of or control your repository in any way.

Afterwards, you can utilize this template as a blueprint for your plugin repository.

Creating your Plugin Repository #

To create a new repository, click on the green button labeled “Use this template” located at the top right of the page. Once you do so, you’ll be prompted to fill in details such as the repository name, owner, and description (optional). You can also establish whether you want it to be public or private.

After a short wait, you’ll be able to clone the new repository onto your machine and commence building your plugin.

A screenshot of GitHub where you can see the screen to create a new repository generated of the template repository

Start Building #

In the repository you will find a README.md file with all the instructions you need. This README tells you what is included in the template and has 10 steps that you will need to take to get your own plugin up and running.

The template repository README file

If you follow those steps you will have a fully functional .NET MAUI repo, a sample app that shows the plugins’ abilities, a README file for your project and a fully functional continuous integration pipeline and automated pipeline to publish your plugin to NuGet 🤯

Just be sure to replace your repository plugin’s feature name everywhere it appears within the repository. This includes replacing occurrences within file and folder names, solution files, NuGet metadata, license author names, and more. Using a tool like VS Code makes the process simpler by automating most of these actions.

Remember, there are already a good number of these plugins out there, so you’re in good company and you have some good examples to turn to for your own. Find a list of the current plugins below.

Conclusion #

Building your own plugins will deepen your knowledge on how .NET MAUI works, including the underlaying platforms. At the same time you’re adding value to the .NET community and empowering others to create their best projects based on your amazing work.

I’m excited to see what plugins you will create with this .NET MAUI Plugin Template! Feel free to reach out to let me know if this guide was helpful, and don’t forget to share details about your fantastic new plugin!