Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using WinForms Controls provided via NuGet inside the Out-Of-Process Designer without copying them to the build output #11319

Open
SteffenSchwaiger opened this issue May 7, 2024 · 6 comments
Assignees
Labels
area-DesignerSupport area-VSDesigner Windows Forms out-of-proc designer related issues tenet-compatibility Incompatibility with previous versions or with WinForms for .NET Framework
Milestone

Comments

@SteffenSchwaiger
Copy link

Environment

17.10.0 Preview 6.0

.NET version

8.0

Did this work in a previous version of Visual Studio and/or previous .NET release?

.NET Framework

Issue description

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?

Steps to reproduce

Install any NuGet package that contains UI controls (e.g. ReaLTaiizor) and try to exclude them from the build output while still being able to use them in the Out-Of-Process Designer.

Diagnostics

No response

@SteffenSchwaiger SteffenSchwaiger added the untriaged The team needs to look at this issue in the next triage label May 7, 2024
@elachlan
Copy link
Contributor

elachlan commented May 7, 2024

You could do something like:

<ItemGroup>
  <PackageReference Include="SomeNuGetPackage" Version="1.0.0"
                    Condition="'$(Configuration)'=='Debug'"/>
</ItemGroup>

OR

<ItemGroup>
  <PackageReference Include="SomeNuGetPackage" Version="1.0.0">
    <Publish>false</Publish>
  </PackageReference>
</ItemGroup>

@elachlan
Copy link
Contributor

elachlan commented May 8, 2024

@Olina-Zhang can your team please test this and make sure a workaround is possible?

@Zheng-Li01
Copy link
Member

@elachlan @SteffenSchwaiger, the below workaround working well that the third part control can be copied to the build output, and the exe can launch successfully.

<ItemGroup>
  <PackageReference Include="SomeNuGetPackage" Version="1.0.0">
    <Publish>false</Publish>
  </PackageReference>
</ItemGroup>

image

And the below workaround will cause the application published failed.

<ItemGroup>
  <PackageReference Include="SomeNuGetPackage" Version="1.0.0"
                    Condition="'$(Configuration)'=='Debug'"/>
</ItemGroup>

image

@SteffenSchwaiger
Copy link
Author

Thanks for the workaround. Although this also means that I have to publish the library on every build if I want a directory without the dependency for debugging purposes, right?

@elachlan elachlan added area-DesignerSupport area-VSDesigner Windows Forms out-of-proc designer related issues tenet-compatibility Incompatibility with previous versions or with WinForms for .NET Framework labels May 9, 2024
@elachlan
Copy link
Contributor

elachlan commented May 9, 2024

I'd say so, yes. I'm not sure how to get around that and the team will need to investigate.

@merriemcgaw
Copy link
Member

@Shyam-Gupta will take a look

@merriemcgaw merriemcgaw removed the untriaged The team needs to look at this issue in the next triage label May 15, 2024
@merriemcgaw merriemcgaw added this to the VS release milestone May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DesignerSupport area-VSDesigner Windows Forms out-of-proc designer related issues tenet-compatibility Incompatibility with previous versions or with WinForms for .NET Framework
Projects
None yet
Development

No branches or pull requests

5 participants