Documentation Center

Best practices when creating a custom PublishPostProcess plugin

Best practices when creating a new publish plugin lets you get the best out of your customization.

Implementation plan

  1. Choose the category of the plugin. For example, if you want the plugin to be triggered after the files are exported to the file system, you need to create a plugin that implements the IPublishPostProcess interface.
  2. Choose the interface to implement. When writing a new custom plugin, you should implement one of the available interfaces:
    1. Implement the IPublishPostProcess when your plugin needs to be called after the files are exported to the file system. This is currently the only supported Publish plugin.
  3. Implement Initialize. Here the plugin should read its parameters and parse their values. In case a value is invalid, the plugin sequence can fail early in the process, before any plugin is executed.
  4. Implement Run. Here you put the main logic of the plugin. Anything that plugin can do is available to it through the context, which includes:
    1. The object that was used to start the publish
    2. Information of where the content and metadata files were exported, so they can be accessed
    3. The condition set used
    4. Output format fields
    5. Whether the publish needs to compare versions
    6. Whether the publish needs to combine multiple languages into one output result
    7. Logging (Use the LogService property of the context to add the logging statement to the standard application log file)
  5. Expose the plugin using the Export attribute to make sure that the plugin engine can discover the plugin.

General best practices

Pass false to any API 2.5 constructor
Make sure to pass one parameter, set to false, to any API 2.5 constructors you use in your plugin. Without this parameter included and set to false, you get a security error. This parameter, initializeCallContext, when set to false, causes the call context to be reused, effectively keeping your code within the same process.
Verify the parameter values in Initialize
If the plugin cannot be executed because some parameters were not provided or have wrong values, the main operation should fail as soon as possible.
Use IshValueType.element for getting and setting field values
This ensures that the element name does not change and is guaranteed to be unique.
Use the items property on the IPublishPostProcessContext
The Items property on the IPublishPostProcessContext can be used to pass data in memory between plugins. However make sure not to let too much data loaded in memory: This can cause the server to run out of memory.
Don't log the processing of every file
Logging every file that is being processed in the event monitor generates too many entries in the Event Log. We recommend you only periodically log the number of files already processed in such a way that it would lead to 10 lines in the event monitor. On the other hand, if the plugin encounters and error, make sure to log the exact file that caused the error.
Think multithread
If your process takes a long time, you might want to use multiple threads: it will improve throughput.
Check cancellation
Check that the publish was not cancelled on a regular basis.