Create Plugin Project
We first need to create a new WinUI
class library in VS
.
Write Default Metadata
Five fillable metadata items are provided by default:
Id
: Plugin IDName
: Plugin nameVersion
: Plugin versionPriority
: Loading order, smaller values load earlierDependencies
: Plugin dependenciesSdkVersion
: (Auto) SDK versionBuiltIn
: (Auto) Whether it's a built-in pluginDllName
: (Auto) DLL file nameMainPlugin
: (Auto) Main plugin typeEntryPoints
: (Auto) Entry points
Metadata items (except Dependencies
) are set in plugin.json
.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>ShadowExample.Plugin.Emoji</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<NoWarn>MSB3277</NoWarn>
<!-- Nuget -->
<PackageId>ShadowExample.Plugin.Emoji</PackageId>
<PluginName>Emoji Plugin</PluginName>
<Version>1.0.0.12</Version>
<!-- PluginMeta -->
</PropertyGroup>
</Project>
Create a new plugin.json
in the root directory.
You can use to get variables from
.csproj
.
Id
must correspond to PackageId
.
{
"Id": "{{ PackageId }}",
"Name": "{{ PluginName }}",
"Version": "{{ Version }}"
}
Note
In <PluginMeta>
, you can use MSBuild
property variables:
The metadata item Dependencies
is used to specify the plugin's dependent plugins
, allowing the plugin to load after its dependent plugins
.
Unlike regular metadata items, it needs to be set in the <ItemGroup>
in .csproj
.
It also serves as the project's nuget
package.
- Must specify
Label="Dependencies"
- Must specify
Need="(1.0,2.0)"
for required version internally
<ItemGroup Label="Dependencies">
<PackageReference Include="ShadowExample.Plugin.Hello" Version="1.2.1.2" Need="(1.0,2.0)" />
<PackageReference Include="ShadowExample.Plugin.World" Version="1.3.0.0" Need="(1.0,2.0)" />
</ItemGroup>
Plugin Main Class
The plugin main class needs to inherit from the custom plugin base class in the plugin loader.
And must use the [MainPlugin]
attribute to specify the plugin main class, which will automatically generate corresponding plugin metadata.
// Example plugin main class
namespace ShadowViewer.Plugin.Local;
[MainPlugin]
public partial class LocalPlugin : PluginBase
{
}
TIP
You can directly use LocalPlugin.MetaData
to get the plugin's metadata information.
Subsequent Development
Next, you can choose to override the default methods in the plugin base class.
Or: