I'm working on a plugin module for a .NET 6 app and I was following this Microsoft Docs guide, however I hit a problem while dynamically loading the plugin assemblies.
I want to achieve the following project structure:
SomeService.PluginBaseSomeServicedepends onSomeService.PluginBaseSomeService.PluginSdkdepends onSomeService.PluginBaseSomePlugindepends onSomeService.PluginSdk
During startup, SomeService scans the configured assemblies for implementations of the IPlugin interface from the SomeService.PluginBase package. SomeApi.PluginSdk provides base classes for plugin implementations and reference to the previously mentioned interface transitively.
According to the guide, to avoid assembly mismatch I need to set
<ItemGroup>
<ProjectReference Include="..\SomeService.PluginBase\SomeService.PluginBase.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
in the project file of SomeService.Sdk to avoid copying the assembly to the output directory.
This works fine, however SomeService.PluginBase is still being copied to the output directory of SomePlugin, as it is a transitive dependency of SomeService.Sdk. Even though IPlugin is in SomeService.PluginBase, SomeService fails to load the plugin due to two different IPlugin types.
Is there a way to prevent this without explicitly listing SomeService.PluginBase as a <ProjectReference> of SomePlugin?