Categories

How to create base plugin

In this part we will create base plugin.

1. Create new project in folder Plugins

2. Add dependencies, right click on your project, select Edit YourProjectName.csproj, your file must contain these lines:

<ItemGroup>
  <ProjectReference Include="..\..\Grand.Core\Grand.Core.csproj">
    <Private>false</Private>
  </ProjectReference>
  <ProjectReference Include="..\..\Grand.Data\Grand.Data.csproj">
    <Private>false</Private>
  </ProjectReference>
  <ProjectReference Include="..\..\Grand.Framework\Grand.Framework.csproj">
    <Private>false</Private>
  </ProjectReference>
  <ProjectReference Include="..\..\Grand.Services\Grand.Services.csproj">
    <Private>false</Private>
  </ProjectReference>
</ItemGroup>  

And these, but you need to modify them by adding your project name

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
  <OutputPath>..\..\Grand.Web\Plugins\Misc.ExamplePlugin\</OutputPath>
  <OutDir>$(OutputPath)</OutDir>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  <OutputPath>..\..\Grand.Web\Plugins\Misc.ExamplePlugin\</OutputPath>
  <OutDir>$(OutputPath)</OutDir>
</PropertyGroup>

3. Rename created class to the name of plugin, and make this class public and inherit from BasePlugin. Every plugin in GrandNode inherits from BasePlugin.

4. Add Description.txt to your project. File should include these fields:

Group: Misc Plugins
FriendlyName: Example Plugin
SystemName: Misc.ExamplePlugin
Version: 1.0
SupportedVersions: 4.50
Author: grandnode team
DisplayOrder: 1
FileName: Grand.Plugin.Misc.ExamplePlugin.dll

5. Add logo.jpg (must be jpg extension)

REMEMBER: Right click on logo and description -> properties -> Copy To Output Directory set to "Copy if newer". It applies to every static file.

6. Add methods from BasePlugin to your main file. Your file should look like this

In main directory of your plugin create file DependencyRegistrar.cs
We will register plugin to container.

 

Congratulations ! 

You created your first plugin. Now rebuild it, and you can install it in admin panel.

back to top