Skip to content

How to build a Server Plugin

Luke edited this page Jul 17, 2018 · 80 revisions

Please see our Development Policy before beginning development.

First install Emby Server, and get it up and running. Install Visual Studio 2017 along with the .NET Core SDK.

Overview

Emby Server runs on two different runtimes: .NET Core 2.0+, and Mono. The following instructions will show you how to build one plugin that will run on all platforms supported by Emby Server.

Create your Visual Studio Solution (VS 2017+)

  1. Create a .NET Standard class library project. This will create a Class1.cs file. Delete this and build the project. The process of building will save all changes to disk.

  2. Once this is done, open up your .csproj file and replace the entire contents with the following:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup> <TargetFrameworks>netstandard2.0;</TargetFrameworks> <AssemblyVersion>1.0.0.0</AssemblyVersion> <FileVersion>1.0.0.0</FileVersion> </PropertyGroup>

<ItemGroup> <PackageReference Include="mediabrowser.server.core" Version="3.5" /> </ItemGroup>

</Project>

This will will add a reference to the Emby nuget package.

  1. Build again to ensure Visual Studio has picked up the external changes.

  2. Use Visual Studio to check for any non-beta updates to the Emby nuget package.

Add Classes

For these next steps, you may wish to refer to an example. The Roku bif plugin is a good example.

  1. Create a class called PluginConfiguration, and have it inherit from MediaBrowser.Model.Plugins.BasePluginConfiguration.

  2. Create a class called Plugin, and have it inherit from MediaBrowser.Common.Plugins.BasePlugin<T>, where T is the name of the PluginConfiguration class you just created. You will need to implement its constructor like so:

public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer)

  1. Create a random GUID using visual studio's Create Guid tool under the Tools menu. In Plugin.cs, override the Id property, and return the guid you just created. This will be the Id for the plugin and can never be changed.

Important - If migrating an existing plugin solution from Visual Studio 2015, then the plugin Id value should come from the AssemblyGuid located in AssemblyInfo.cs of your 2015 project.

Create a Post-Build Event

Right click the project -> Properties. Create a post-build event that will copy the assembly to the server's plugins directory. For example:

xcopy "$(TargetPath)" "%AppData%\Emby-Server\Plugins\" /y

Test the Plugin

Shutdown the server, rebuild your solution, and restart the server. At this point you should see your plugin in the Dashboard's Plugins menu.

Add Functionality

To add real functionality to your plugin, you will need an entrypoint that can initialize and accept the various dependencies you may need in order to interact with the MB environment.

This is done by creating a class that implements the IServerEntryPoint interface. See Automatic Type Discovery for this and other types you can include in your plug-in. Its constructor can accept any number of injected dependencies - depending on what your plugin needs to access. See Dependency Injection.

If your plugin will be a premium plugin, see IRequiresRegistration in Other Interfaces.

In addition, use these Emby interfaces when applicable:

  • IFileSystem
  • IHttpClient
  • INetworkManager
  • IProcessFactory
  • IZipClient

Debugging

The quickest way to test code changes is to work without the debugger. If you do this, you can leave the server running at all times. Simply use the Rebuild command on your plugin project, and right click the server tray -> Restart Server. If that option is not visible you'll need to enable developer tools in the Dashboard under Advanced.

Clone this wiki locally