Skip to content
maforget edited this page Nov 26, 2026 · 13 revisions

.NET plugin samples

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.

Plugin Types

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.

Write a plugin class

  • 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 DotNetPlugin class contains properties you can override, the Key property is required to override. Name, Description, Image, Enabled and PCount are optional, and Name defaults to the Key. PCount is the number of parameters of an ICreateBookList hook.
  • The class must be public, not abstract and not generic.
  • The class requires a public constructor without parameters. The DotNetPlugin base class has the properties ComicRack (the host) and ScriptPath (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 properties ComicRack (the host) and ScriptPath (the plugin folder) are null before OnLoad.
  • If the class implements IDisposable, ComicRack calls Dispose when 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 Execute signature, for example ILibrary, IEditor, IBooks and INewBooks. To give each hook its own code, implement the interfaces explicitly: void IBooks.Execute(ComicBook[] books) { ... }.
  • The Key must be unique. ComicRack skips a plugin whose Key another plugin or script already uses.
  • The DotNetPlugin class also contains a Log method 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 Image property can be an image file (like with Python plugins) or can be an EmbeddedResource inside a compiled DLL. It will only try to use the EmbeddedResource if no image file exists.

To see the messages of plugins and compile errors, start ComicRack with the script console: ComicRack.exe -ssc.

Plugin API version

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.Version is the newest API version of the running ComicRack. PluginApi.MinimumVersion is the oldest one it still supports. Both are 1 today.
  • ComicRack skips a plugin that declares a version above PluginApi.Version or below PluginApi.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.

Source plugins

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 .cs files of the folder and its subfolders into one assembly. It ignores the subfolders bin and obj.
  • References lists the DLLs that the plugin ships, relative to the plugin folder.
  • FrameworkReferences lists 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 as System, System.Core, System.Drawing and System.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 .csplugin file 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>.dll and .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 the Debug configuration. 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 init accessors and records (with some limitations).
  • LangVersion refers to the language version that the script uses. Normally .NET Framework 4.8 uses 7.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 as latest or specific version such as 14.0. Omitting such a value will default to 14.0. Using latest is 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.

Translate a plugin

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.

  1. Make a folder with the name of the language next to the plugin: de, or de-DE for a regional variant. The plugin folder is the folder of the DLL, or the folder of the .csplugin file.
  2. Put a file <Key>.xml in it. <Key> is the Key of the DotNetPlugin class. The de folder can also be a de.zip file that holds the XML file.
  3. Write one Text entry for each text. Key is the element key, Text is the translation, and Comment is 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 Name and Description translate the Name and the Description of the DotNetPlugin instance.
  • ComicRack.Localize(Key, "Greeting", "Hello") returns Hallo in 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>.xml in its own Languages\<language> folder, then for <Key>.xml there. 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.

Third-party DLLs

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 reference Some.dll is then found as Some.dll in 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.

Debugging a plugin

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.

  1. Start ComicRack. For a source plugin, start it with -dso (see the table below). Adding -ssc is also handy to see plugin messages and compile errors: ComicRack.exe -dso -ssc.
  2. In Visual Studio, open Debug > Attach to Process... (Ctrl+Alt+P).
  3. Select ComicRack.exe. Plugins run on .NET Framework 4.8, so make sure the code type is Managed (.NET Framework 4.x).
  4. Click Attach.
  5. Put a breakpoint in your code and run the hook from ComicRack.
  6. 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.

Check that symbols are loaded

In the Modules window, find your plugin's DLL and look at its columns:

  • Symbol Status should say Symbols loaded. If it says Symbols 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. A Yes here means the plugin was built in Release, and with Just My Code enabled the debugger will skip it, even if the .pdb is found.
  • Path shows where the DLL was loaded from. For a source plugin this is ComicRack's cache folder, which is also where the .pdb is 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 plugins vs compiled plugins

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.

Without -dso: disable Just My Code

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:

  1. Open Tools > Options > Debugging > General.
  2. Uncheck Enable Just My Code.
  3. 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.

Clone this wiki locally