microsoft/winforms-designer-extensibility

.NET 8 Plugin Extensions: Leveraging WinForms Controls from Main Application inside the Designer

Opened this issue · 1 comments

I cannot find a way to use WinForms controls inside my plugin project that are provided by the main application without including them in the project build output and therefore also distributing them via dotnet publish. They are only "compile time" dependencies as they are provided by the main application when the plugin is loaded inside it.

In the .NET Framework, I was able to provide the WinForms controls inside a NuGet package in the ref folder so that they were not copied to the build output. After wondering why this did not work after migrating to .NET 8, I finally found the Control Library NuGet Package Spec and found out that they need to be distributed inside the lib folder because the new WinForms Out-Of-Process .NET Designer needs them at "runtime".

This requirement conflicts with the documentation on how to structure plugin projects available here: Create a .NET Core application with plugins, as it says there:

Let's say that there is an app A that has a plugin interface defined in the NuGet package named A.PluginBase. How do you reference the package correctly in your plugin project? [...] To correctly reference the A.PluginBase package, you want to change the element in the project file to the following:

<PackageReference Include="A.PluginBase" Version="1.0.0">
    <ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>

This prevents the A.PluginBase assemblies from being copied to the output directory of your plugin and ensures that your plugin will use A's version of A.PluginBase.

When I use <ExcludeAssets>runtime</ExcludeAssets> for my winforms control library, the lib content is not copied to the build output anymore (good), but the WinForms Out-Of-Process .NET Designer is also not working anymore (bad). The controls are listed inside the toolbox, but fail to be instanciated which might be expected by the current architecture.

What is the suggested approach for solving this constellation?

The exact same problem already existed almost 2 years ago, so nothing changed in the meantime?

[...] As a rule, the design-time functionality for a commercial control is implemented in a separate DLL not intended for redistribution with end-user apps. [...] But this means that the design-time DLL will be copied to the bin folder with the compiled app and, as it often happens, redistributed with the app.

Source: .NET Blog | State of the Windows Forms Designer for .NET Applications