.NET 6 exclude runtime assets of transitive dependencies

Viewed 265

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.PluginBase
  • SomeService depends on SomeService.PluginBase
  • SomeService.PluginSdk depends on SomeService.PluginBase
  • SomePlugin depends on SomeService.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?

0 Answers
Related