UNLEASH THE POWER OF CODE REUSE
Creating Plugins For Xamarin
Yu Guan | Microsoft MVP
Meet Yu Guan | @askguanyu
twitter.com/askguanyu
linkedin.com/in/yuguan
askguanyu.wordpress.com
devlib.codeplex.com
Microsoft MVP
Speaker, Blogger, Hacker, Coder, Maker, Gamer
Azure, IoT, Cross-platform Apps, GIS, Services
WHAT IS A PLUGIN FOR XAMARIN?
 Abstract platform specific functionality API
 Small
 Cross-platform
 Minimal-to-no dependencies
 Accessed via PCL or Shared Projects
WALKTHROUGH
Get Visual Studio Extensions - Plugin For Xamarin Templates
Create Plugin For Xamarin Templates projects
Implement your plugin
Add nuspec file
Nuget pack
Test (optional)
Nuget push
Sync to GitHub (optional)
PLUGIN FOR XAMARIN TEMPLATES
 https://visualstudiogallery.msdn.microsoft.com/afead421-3fbf-489a-a4e8-
4a244ecdbb1e
CREATE PROJECTS
IMPLEMENT YOUR PLUGIN
/// <summary>
/// Interface for MyPlugin1
/// </summary>
public interface IMyPlugin1
{
bool IsConnected { get; set; }
void PlaySound();
string GetDeviceInfo();
}
/// <summary>
/// Implementation for MyPlugin1
/// </summary>
public class MyPlugin1Implementation : IMyPlugin1
{
public bool IsConnected
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void PlaySound()
{
throw new NotImplementedException();
}
public string GetDeviceInfo()
{
throw new NotImplementedException();
}
}
ADD NUSPEC FILE
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.3">
<id>Plugin.MyPlugin1</id>
<version>1.0.0</version>
<title>MyPlugin1 Plugin for Xamarin and Windows</title>
<authors>Your Name</authors>
<owners>Your Name</owners>
<licenseUrl/>
<projectUrl/>
<!--Default Icon, a template can be found: https://raw.githubusercontent.com/jamesmontemagno/Xamarin-Templates/master/Plugins-Templates/icons/pl
<iconUrl>https://raw.githubusercontent.com/jamesmontemagno/Xamarin-Templates/master/Plugins-Templates/icons/plugin_icon_nuget.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
Long description for your plugin.
</description>
<summary>Short description for your plugin.</summary>
<tags>xamarin, pcl, xam.pcl, plugin, plugin for xamarin, windows phone, winphone, wp8, winrt, android, xamarin.forms, ios</tags>
<dependencies>
<group targetFramework="net">
</group>
<group targetFramework="win">
</group>
<group targetFramework="wp">
</group>
<group targetFramework="wpa">
</group>
<group targetFramework="MonoAndroid">
</group>
<group targetFramework="Xamarin.iOS10">
</group>
<group targetFramework="Xamarin.Mac20">
</group>
<group targetFramework="portable-net45+win+wpa81+wp80">
</group>
<group targetFramework="uap">
</group>
<group targetFramework="dotnet">
PACKAGING AND PUBLISHING NUGET PACKAGE
 https://docs.nuget.org/Create/Creating-and-Publishing-a-Package
 nuget.exe update –self
 nuget.exe setApiKey “your key”
 nuget.exe pack YourPackage.nuspec
 nuget.exe push YourPackage.nupkg -Source https://www.nuget.org/api/v2/package
GitHub
TIME TO CODE
Thank You!

Unleash the power of code reuse - creating plugins for Xamarin

  • 1.
    UNLEASH THE POWEROF CODE REUSE Creating Plugins For Xamarin Yu Guan | Microsoft MVP
  • 2.
    Meet Yu Guan| @askguanyu twitter.com/askguanyu linkedin.com/in/yuguan askguanyu.wordpress.com devlib.codeplex.com Microsoft MVP Speaker, Blogger, Hacker, Coder, Maker, Gamer Azure, IoT, Cross-platform Apps, GIS, Services
  • 3.
    WHAT IS APLUGIN FOR XAMARIN?  Abstract platform specific functionality API  Small  Cross-platform  Minimal-to-no dependencies  Accessed via PCL or Shared Projects
  • 4.
    WALKTHROUGH Get Visual StudioExtensions - Plugin For Xamarin Templates Create Plugin For Xamarin Templates projects Implement your plugin Add nuspec file Nuget pack Test (optional) Nuget push Sync to GitHub (optional)
  • 5.
    PLUGIN FOR XAMARINTEMPLATES  https://visualstudiogallery.msdn.microsoft.com/afead421-3fbf-489a-a4e8- 4a244ecdbb1e
  • 6.
  • 7.
    IMPLEMENT YOUR PLUGIN ///<summary> /// Interface for MyPlugin1 /// </summary> public interface IMyPlugin1 { bool IsConnected { get; set; } void PlaySound(); string GetDeviceInfo(); } /// <summary> /// Implementation for MyPlugin1 /// </summary> public class MyPlugin1Implementation : IMyPlugin1 { public bool IsConnected { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public void PlaySound() { throw new NotImplementedException(); } public string GetDeviceInfo() { throw new NotImplementedException(); } }
  • 8.
    ADD NUSPEC FILE <?xmlversion="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata minClientVersion="2.8.3"> <id>Plugin.MyPlugin1</id> <version>1.0.0</version> <title>MyPlugin1 Plugin for Xamarin and Windows</title> <authors>Your Name</authors> <owners>Your Name</owners> <licenseUrl/> <projectUrl/> <!--Default Icon, a template can be found: https://raw.githubusercontent.com/jamesmontemagno/Xamarin-Templates/master/Plugins-Templates/icons/pl <iconUrl>https://raw.githubusercontent.com/jamesmontemagno/Xamarin-Templates/master/Plugins-Templates/icons/plugin_icon_nuget.png</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description> Long description for your plugin. </description> <summary>Short description for your plugin.</summary> <tags>xamarin, pcl, xam.pcl, plugin, plugin for xamarin, windows phone, winphone, wp8, winrt, android, xamarin.forms, ios</tags> <dependencies> <group targetFramework="net"> </group> <group targetFramework="win"> </group> <group targetFramework="wp"> </group> <group targetFramework="wpa"> </group> <group targetFramework="MonoAndroid"> </group> <group targetFramework="Xamarin.iOS10"> </group> <group targetFramework="Xamarin.Mac20"> </group> <group targetFramework="portable-net45+win+wpa81+wp80"> </group> <group targetFramework="uap"> </group> <group targetFramework="dotnet">
  • 9.
    PACKAGING AND PUBLISHINGNUGET PACKAGE  https://docs.nuget.org/Create/Creating-and-Publishing-a-Package  nuget.exe update –self  nuget.exe setApiKey “your key”  nuget.exe pack YourPackage.nuspec  nuget.exe push YourPackage.nupkg -Source https://www.nuget.org/api/v2/package
  • 10.
  • 11.
  • 12.