Jim Bennett
Xamarin MVP Microsoft MVP

Mobile developer at EROAD, Xamarin MVP and Certified Developer, Microsoft MVP, author of Xamarin In Action, blogger, speaker, father and lover of beer, whisky and Thai food. Opinions are my own.

  Auckland, New Zealand
Xamarin In Action
  Xamarin In Action
  Twitter
  GitHub
  LinkedIn
  YouTube
  Email
  CV

In the first part of this set of posts I looked at creating a dotnet new project template, and in the second part I showed how you could easily add this to a Visual Studio for Windows extension. Lets now look at adding it to a Visual Studio for Mac extension, so that our template is available everywhere.

It's really easy to create extensions for VS for Mac for new project types. In a previous blog post I discussed the old way of doing it which, like for VS on Windows, involved a load of files that couldn't be compiled as they had replacement tokens, and no easy way to test the output projects without debugging the extension.

This all changes now. Instead of adding all the project files, you just need to add the NuGet package created for dotnet new with a build action of Add-In File, then add an entry into the Manifest.addin.xml file to make it available:

<Extension path="/MonoDevelop/Ide/Templates">  
  <Template
    id="MvvmCrossNativeSinglePage.CSharp"
    _overrideDescription="Creates a new single page native MvvmCross app."
    path="Templates/MvvmCross.Templates.CSharp.Native.SinglePage.iOS.Android.nupkg"
    category="other/net/mvvmcross"
    icon="res:MVVMCross.XSAddIn.Icons.MvvmCross.png"/>
  </Extension>

This manifest entry provides a description to show in the File->New dialog, the category in that dialog to put the template into, an icon and the path in the addin to the NuGet package. You can add as many NuGet packages as you want, with one Template entry per NuGet package. And that's it - no need to add the project files, xpt.xml files or anything hard like that. You can see an example of this with my MvvmCross templates on my GitHub.




About the Author

Jim Bennett

International C# and Xamarin geek - Microsoft MVP, Xamarin MVP and Certified Developer, blogger, speaker, father and lover of beer, whisky and Thai food

 

In the first part of this set of posts I looked at creating a dotnet new project template, and in the second part I showed how you could easily add this to a Visual Studio for Windows extension. Lets now look at adding it to a Visual Studio for Mac extension, so that our template is available everywhere.

It's really easy to create extensions for VS for Mac for new project types. In a previous blog post I discussed the old way of doing it which, like for VS on Windows, involved a load of files that couldn't be compiled as they had replacement tokens, and no easy way to test the output projects without debugging the extension.

This all changes now. Instead of adding all the project files, you just need to add the NuGet package created for dotnet new with a build action of Add-In File, then add an entry into the Manifest.addin.xml file to make it available:

<Extension path="/MonoDevelop/Ide/Templates">  
  <Template
    id="MvvmCrossNativeSinglePage.CSharp"
    _overrideDescription="Creates a new single page native MvvmCross app."
    path="Templates/MvvmCross.Templates.CSharp.Native.SinglePage.iOS.Android.nupkg"
    category="other/net/mvvmcross"
    icon="res:MVVMCross.XSAddIn.Icons.MvvmCross.png"/>
  </Extension>

This manifest entry provides a description to show in the File->New dialog, the category in that dialog to put the template into, an icon and the path in the addin to the NuGet package. You can add as many NuGet packages as you want, with one Template entry per NuGet package. And that's it - no need to add the project files, xpt.xml files or anything hard like that. You can see an example of this with my MvvmCross templates on my GitHub.