Referencing optional assembly definitions in a package

Hi, I’d like to optionally support some 3rd party plugins in my package. In non-package-world I would just add some #if defs for the relevant code. I’m still doing that, but I don’t see any way to establish a link between my package and the 3rd party code short of adding an Assembly Definition Reference directly to my Assembly Definition file. But adding that reference seems wrong, as it may not always be present? And if I require end-users to add it won’t it be overridden by the package manager? What’s the recommended way to support 3rd party code in my package?

Hi @spottedzebra ,

When the optional reference is coming from another package, the right approach is to use Version defines to create specific symbols to #if onto. It also requires to set the assembly definition reference in the package asmdef file(s). But in your case, your optional dependency is coming from a plugin. In this case, you cannot use Version defines and need to rely on documented symbols from the plugin author. As for assembly definition reference, you are correct. You need to put it in your package even though the assembly may not be in the project where your package is installed. Don’t worry, it will only log a warning if the assembly from the plugin is not installed and your #if directives will make your code compile without errors.

Hope it helps,

Pascal

2 Likes