Repository navigation
.NET plugin
- .NET plugin samples
- Plugin Types
- Write a plugin class
- Plugin API version
- Source plugins
- Translate a plugin
- Third-party DLLs
- Debugging a plugin
A .NET plugin is a class that derives from DotNetPlugin and implements one or more hook interfaces, for example IBooks or IComicInfoHtml. ComicRack gives the class one command for each hook interface.
public class MyPlugin : DotNetPlugin, ILibrary, IEditor, IBooks, IConfig
{
public override string Key { get; set; } = "MyPlugin";
public override string Description { get; set; } = "Does something";
// You can ship both light/dark mode image and it will load them automatically based on your theme.
// Just prefix your dark image with 'Dark'.
public override string Image => "MyPlugin.png";
// Implementation only for the Editor hook.
// Notice the explicit implementation, so it's only used for the IEditor hook.
void IEditor.Execute(ComicBook[] books)
{
MessageBox.Show($"Running from Editor on Book: {books.FirstOrDefault()?.Caption}");
}
// Implementation for the other hooks. Including ILibrary & IBooks.
// It will serve as entry point for all hooks that match the same signature.
public void Execute(ComicBook[] books)
{
MessageBox.Show($"Executing plugin on {(books.Count())} books.");
}
void IConfig.Execute()
{
MessageBox.Show($"Running Config");
}
}See this SamplePlugin repo for a template project to get you started.
You can ship a plugin in two forms. Both use the same classes and interfaces.
| Form | What you ship |
|---|---|
| Source plugin | A folder with a <Name>.csplugin file and .cs files. ComicRack compiles it. |
| Compiled plugin | A DLL that you build. |
Prefer a source plugin. Users can read what it does and can modify it themselves easily.
- Create a class that derives from
DotNetPlugin. - Implement a Valid Hooks to that class. Hooks are the entry point where the plugin is ran.
- The
DotNetPluginclass contains properties you can override, theKeyproperty is required to override.Name,Description,Image,EnabledandPCountare optional, andNamedefaults to theKey.PCountis the number of parameters of anICreateBookListhook. - The class must be public, not abstract and not generic.
- The class requires a public constructor without parameters. The
DotNetPluginbase class has the propertiesComicRack(the host) andScriptPath(the plugin folder). Same usage than those same variables used in IronPython plugins. - ComicRack creates one instance of every plugin class when it scans the script folders, also for a plugin that is disabled.
- The instance is shared by all hooks of the class and lives until ComicRack closes.
- Do the initialization in
OnLoad. The propertiesComicRack(the host) andScriptPath(the plugin folder) are null beforeOnLoad. - If the class implements
IDisposable, ComicRack callsDisposewhen it closes. - ComicRack skips a class that does not follow these rules and writes the reason to the script console. This includes a class that doesn't derives from
DotNetPlugin. - Some hooks have the same
Executesignature, for exampleILibrary,IEditor,IBooksandINewBooks. To give each hook its own code, implement the interfaces explicitly:void IBooks.Execute(ComicBook[] books) { ... }. - The
Keymust be unique. ComicRack skips a plugin whoseKeyanother plugin or script already uses. - The
DotNetPluginclass also contains aLogmethod you can use to output to the script console (using-ssc). It will prefix the message with which method called it. Example:[SamplePlugin..ctor] Creating Constructor. - The
Imageproperty can be an image file (like with Python plugins) or can be anEmbeddedResourceinside a compiled DLL. It will only try to use theEmbeddedResourceif no image file exists.
To see the messages of plugins and compile errors, start ComicRack with the script console: ComicRack.exe -ssc.
The plugin API is the set of attributes and interfaces in ComicRack.Plugins.dll. Its assembly version changes with every build, so it cannot tell a plugin whether it fits. Declare the API version your plugin was written for, once, in any of its files:
[assembly: PluginApiVersion(1)]-
PluginApi.Versionis the newest API version of the running ComicRack.PluginApi.MinimumVersionis the oldest one it still supports. Both are 1 today. - ComicRack skips a plugin that declares a version above
PluginApi.Versionor belowPluginApi.MinimumVersion. It writes a message with both versions to the script console. It reads the declaration without running code of the plugin, so a skipped plugin is never loaded. - A plugin without the attribute counts as version 1 and loads. Add the attribute to say which API you wrote the plugin against.
- The same rule applies to source plugins. A plugin that uses a newer API usually fails to compile, and a message about a compile error then replaces the version message.
The .csplugin file marks the folder as a source plugin. Its name is the name of the plugin. It is an INI file, and all entries are optional:
[Plugin]
References=Some.dll;Other.dll
FrameworkReferences=System.Web;SharpCompress
LangVersion=14.0- ComicRack compiles all
.csfiles of the folder and its subfolders into one assembly. It ignores the subfoldersbinandobj. -
Referenceslists the DLLs that the plugin ships, relative to the plugin folder. -
FrameworkReferenceslists more assemblies of the .NET Framework or that ComicRack uses itself. It also looks into your library paths you've set in Preferences. ComicRack always adds the common ones, such asSystem,System.Core,System.DrawingandSystem.Windows.Forms, and its own plugin API. - ComicRack does not load a DLL in the folder of a source plugin as a plugin. The source is the plugin.
- ComicRack keeps the compiled assembly in its cache folder and compiles again when a source file, the
.cspluginfile or a reference changes. - A compile error is written to the script console with file, line and column, and ComicRack skips the plugin.
- A compile warning is written to the script console after the line "Compiling source plugin", followed by the number of warnings. ComicRack compiles only when something changed, so a start from the cache writes no warnings. At start, it deletes the cached assemblies (
<Name>-<folder>-<key>.dlland.pdb) of plugins that no script folder contains any more, and leaves other files in the cache folder alone. - Running ComicRack with
DisableScriptOptimization(-dso) will force the plugin to be compiled with theDebugconfiguration. Switching configuration will invalidate your cached assemblies. Contrary to IronPython this option doesn't prevent you from having to restart ComicRack. Newer version of your plugin will need to be recompiled so restarting is mandatory to see changes regardless of that option. - Plugins run on .NET Framework 4.8, but will inject the PolySharp package into the compiled plugin. That packages let's you use newer language features that need a newer runtime, such as
initaccessors and records (with some limitations). -
LangVersionrefers to the language version that the script uses. Normally .NET Framework 4.8 uses7.3, some newer language are enabled by either the compiler or by package such as PolySharp that this projects uses. You can use value such aslatestor specific version such as14.0. Omitting such a value will default to14.0. Usinglatestis not recommended and you should always use a specific version.
From the MS site about LangVersion:
Warning
Setting the LangVersion element to latest is discouraged. The latest setting means the installed compiler uses its latest version. The value of latest can change from machine to machine, making builds unreliable. In addition, it enables language features that might require runtime or library features not included in the current SDK.
Warning
When installing a .crplugin ComicRack will flatten the folder so any folder structure will be lost. So make sure that you don't have files that have identical names into subfolders. When compiling what really matters is the namespace and not where the files are located.
ComicRack translates the name and the description of a command, and the texts that a plugin passes to ComicRack.Localize(key, elementKey, text). It uses the same language files as Python scripts. No code is needed for the name and the description.
- Make a folder with the name of the language next to the plugin:
de, orde-DEfor a regional variant. The plugin folder is the folder of the DLL, or the folder of the.cspluginfile. - Put a file
<Key>.xmlin it.<Key>is theKeyof theDotNetPluginclass. Thedefolder can also be ade.zipfile that holds the XML file. - Write one
Textentry for each text.Keyis the element key,Textis the translation, andCommentis the original text.
<?xml version="1.0"?>
<TR Name="MyPlugin" CultureName="de">
<Texts>
<Text Key="Name" Text="Mein Plugin" Comment="My Plugin" />
<Text Key="Description" Text="Tut etwas" Comment="Does something" />
<Text Key="Greeting" Text="Hallo" Comment="Hello" />
</Texts>
</TR>- The element keys
NameandDescriptiontranslate theNameand theDescriptionof theDotNetPlugininstance. -
ComicRack.Localize(Key, "Greeting", "Hello")returnsHalloin German. It returns the text from the code when the language has no file or no entry, so the code always contains the English text. - A regional file adds to the file of the main language and wins where both have an entry.
- If the plugin folder has no file for the language, ComicRack looks for
Script.<Key>.xmlin its ownLanguages\<language>folder, then for<Key>.xmlthere. A plugin that ships with ComicRack uses this. - ComicRack reads the files again only when it starts.
Warning
As with the above warning about folder structure being lost when installing a .crplugin, any language folder will be lost. So you should prioritize packaging your translation via .zip file instead.
Put the DLLs that your plugin needs into the plugin folder. For a source plugin, also list them in References. It also looks into the library paths you've set in Preferences. For a source plugin it will search for FrameworkReferences inside these library paths.
- A package file (
.crplugin) is installed into one folder without subfolders. A referenceSome.dllis then found asSome.dllin the plugin folder. - ComicRack loads a DLL without a strong name once for each name. If two plugins ship different versions of such a DLL, both plugins use the version that is needed first. The script console shows a warning.
- Different versions of a strong-named DLL load side by side, so each plugin gets its own version.
Use Visual Studio Community 2026 (or any other edition) to debug a plugin. Visual Studio Code is not recommended for C# projects: its debugging support for .NET Framework is limited, and attaching to ComicRack and getting symbols to load is much less reliable.
- Start ComicRack. For a source plugin, start it with
-dso(see the table below). Adding-sscis also handy to see plugin messages and compile errors:ComicRack.exe -dso -ssc. - In Visual Studio, open Debug > Attach to Process... (
Ctrl+Alt+P). - Select
ComicRack.exe. Plugins run on .NET Framework 4.8, so make sure the code type is Managed (.NET Framework 4.x). - Click Attach.
- Put a breakpoint in your code and run the hook from ComicRack.
- Open Debug > Windows > Modules (
Ctrl+Alt+U) to check that your plugin is loaded and its symbols are found. The window is only available while a debug session is running.
In the Modules window, find your plugin's DLL and look at its columns:
-
Symbol Status should say
Symbols loaded. If it saysSymbols not loaded, right-click the module and use Load Symbols, or check the Symbol File path to see where the debugger is looking. -
Optimized should be
No. AYeshere means the plugin was built inRelease, and with Just My Code enabled the debugger will skip it, even if the.pdbis found. -
Path shows where the DLL was loaded from. For a source plugin this is ComicRack's cache folder, which is also where the
.pdbis written. If a breakpoint shows as hollow with a warning ("The breakpoint will not currently be hit"), the symbols are not loaded or the module is considered optimized.
| Source plugin | Compiled plugin | |
|---|---|---|
| Who builds it | ComicRack, when it starts | You, in Visual Studio |
| Configuration |
Release by default. Start ComicRack with -dso to compile with Debug. |
Whatever you build. Use Debug while debugging. |
Symbols (.pdb) |
Written to the cache folder next to the cached assembly | Next to your DLL in the plugin folder |
| Required to debug | Start ComicRack with -dso, or disable Just My Code (see below) |
Build in Debug, or disable Just My Code if you debug a Release build |
| After changing code | Restart ComicRack so it recompiles | Rebuild, then restart ComicRack |
Source plugins. Start ComicRack with -dso (DisableScriptOptimization) so the plugin is compiled with the Debug configuration. Switching configuration invalidates the cached assemblies, so the first start after adding or removing -dso recompiles everything. Unlike IronPython, -dso does not let you skip restarting: you must restart ComicRack to see any change.
Compiled plugins. Build the DLL in Debug and make sure the .pdb is copied next to it in the plugin folder. The provided SamplePlugin should copy the .pdb automatically when building in Debug. No command line argument is needed.
If you can't or don't want to start ComicRack with -dso, for example when debugging a plugin that was compiled in Release, you can still debug it by turning off Just My Code:
- Open Tools > Options > Debugging > General.
- Uncheck Enable Just My Code.
- Attach again and check the Modules window.
With Just My Code enabled, Visual Studio treats optimized modules as non-user code and ignores their breakpoints, even when a .pdb exists. Disabling it makes the debugger load the symbols anyway. Keep in mind that optimized code can behave oddly while stepping (variables unavailable, lines skipped), so -dso or a Debug build gives a better experience.
- Home
- Android
- New Features
- Frequently Asked Question
- References
- Plugin Development
- Localization