dotnet / windowsdesktop

MIT License
162 stars 54 forks source link

FrameworkReference Microsoft.WindowsDesktop.App.WindowsForms Incorrectly Includes WindowsFormsIntegration.dll #4789

Open lonitra opened 3 days ago

lonitra commented 3 days ago

In .NET 9 we are experiencing issues where when adding <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" /> in a winUI project and building, it tries to resolve System.Xaml even though WinForms does not reference Xaml. This is occurring because we had changed WindowsFormsIntegration.dll to have profile with WPF and WindowsForms causing ResolveAssemblyReferences target to include WindowsFormsIntegration.dll in references thus pulling this .dll in even though it is only intended when no profile is specified i.e. UseWindowsForms and UseWPF is true as indicated in https://github.com/dotnet/wpf/blob/bbfc24fd13804a191e20064acd599b0a359092df/packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props#L45-L46. In .NET 8 there was no profile attribute for this dll.

We had made this update as part of https://github.com/dotnet/windowsdesktop/pull/4227 to support runtime pack respecting profiles when publish self contained winforms/wpf app (https://github.com/dotnet/sdk/issues/37088)

Repro project: App11.zip

Repro steps:

  1. unzip and build project via command line with msbuild -p:platform=x64 -bl
  2. Observe failure about trying to resolve System.Xaml
  3. If we look at the binlog, failure occurs under MarkupCompilePass1 target, specifically in CompileXaml task. For that task, if we look at Parameters > ReferenceAssemblies we can see WindowsFormsIntegration.dll
  4. If we search ReferencePath (this is what the ReferenceAssemblies parameter is in the targets file), we can see WindowsFormsIntegration.dll first gets added in ResolveAssemblyReferences target, specifically ResolveAssemblyReference task
  5. In .NET 8 binlog which is included in zip observe WindowsFormsIntegration.dll is not included in ReferencePath

More info: This was originally reported via https://github.com/dotnet/maui/issues/25883 but scenario can be simplified which is what the repro project demonstrates

lonitra commented 2 days ago

Reopening for pending port to 9.0