dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.75k stars 1.07k forks source link

ImplicitUsings adds usings for both WPF and WinForms if UseWindowsForms is enabled in a WPF project #37608

Open ivansupport opened 11 months ago

ivansupport commented 11 months ago

Problem

The ImplicitUsings property (enabled by default) negatively affects DevExpress customers because our WPF products depend on Windows Forms assemblies. When you create a new WPF project or enable ImplicitUsings in an existing project, the following error occurs because usings for both WPF and Windows Forms are added:

error CS0104: 'Application' is an ambiguous reference between 'System.Windows.Forms.Application' and 'System.Windows.Application'

This issue affects ALL DevExpress WPF customers who either create a new WPF project for .NET or enable ImplicitUsings in an existing project. Our estimate is that more than 50% of WPF customers will be affected by this issue, so we consider it serious/urgent.

You can reproduce the issue as follows:

Approach 1

Approach 2

Suggestion

Check the project type in order not to add Windows Forms usings to WPF projects.

Alexgoon commented 6 months ago

I'm curious if there are any updates or plans regarding this issue. It's still a serious problem since it disrupts the flow for many new users creating a new WPF project and the workaround is not obvious for them.

mr-sven commented 4 months ago

Found the answer on StackOverflow:

  <ItemGroup>
    <Using Remove="System.Windows.Forms" />
  </ItemGroup>
modmynitro commented 1 week ago

It would be nice if we do not need to use workarounds. UseWpf should work out of the box. The error also occurs if UseWindowsForms is not present.

I am currently setting UseWindowsForms to false to workaround the problem.