Skip to content

Add warnings to Microsoft.NET.Sdk.WindowsDesktop to improve UseWpf/UseWinforms and multi-targeting experience #1027

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

Merged
merged 5 commits into from
Jun 24, 2019

Conversation

vatsan-madhavan
Copy link
Member

Fixes the following:

Also cleans up the way in which we import Microsoft.WinFX.targets - UseLegacyPresentationBuildTasks has been broken for some time now and unusable.

@ghost ghost requested review from rladuca, ryalanms and stevenbrix June 20, 2019 00:19
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Jun 20, 2019
@vatsan-madhavan
Copy link
Member Author

/cc @davidwengier, @davkean

@vatsan-madhavan vatsan-madhavan self-assigned this Jun 20, 2019
- #685: Remove **/*.xaml from None
- #327: Cannot multi-target netcoreap < 3.0 and use WindowsDesktop SDK unconditionally.
- #867: Show error when neither UseWpf nor UseWindowsForms is set to true
- #746: [Epic] Support WPF and WinForms specific FrameworkReferences a Profiles

Also cleans up the way in which we import Microsoft.WinFX.targets - UseLegacyPresentationBuildTasks has been broken for some time now and unusable.
- Make the condition in _WindowsDesktopFrameworkRequiresUseWpfOrUseWindowsForms specific to applicable TFM's
@vatsan-madhavan vatsan-madhavan force-pushed the dev/vatsan/windowsdesktopsdkwarnings branch from 27b83c6 to 5db998a Compare June 21, 2019 16:20
Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have tests covering these fixes, for example that you can multitarget .NET Core 2.x and 3.0 using the WindowsDesktop SDK. Do you have a way of testing the WindowsDesktop SDK in this repo?

@vatsan-madhavan vatsan-madhavan force-pushed the dev/vatsan/windowsdesktopsdkwarnings branch from 96b5347 to 0aa98ff Compare June 21, 2019 18:41
@vatsan-madhavan
Copy link
Member Author

It would be nice to have tests covering these fixes, for example that you can multitarget .NET Core 2.x and 3.0 using the WindowsDesktop SDK. Do you have a way of testing the WindowsDesktop SDK in this repo?

Not yet. I'll sync with you next week to figure out how to seed this repo with some tests based off of dotnet/sdk.

For now, these are tested locally using a WPF app, WinForms app and a Console App, and using dotnet, msbuild and VS.

<!-- WPF project -->
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>netcoreapp3.0;net40;net45;net46;net452;net472;netcoreapp2.2;net35</TargetFrameworks>
    <UseWPF>true</UseWPF> <!-- change to false to test NETSDK1106 -->
    <UseWindowsForms>false</UseWindowsForms>
    <SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
  </PropertyGroup>

<PropertyGroup>
  <!--<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1096;NETSDK1105;NETSDK1107</MSBuildWarningsAsMessages>-->
  <!--<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1105</MSBuildWarningsAsMessages>-->
</PropertyGroup>

  <PropertyGroup>
    <FrameworkPathOverride Condition="$(TargetFramework.StartsWith('net3'))">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
  </PropertyGroup>
...
</Project>
<!-- WinForms project -->
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks Condition="'$(MSBuildRuntimeType)'!='Core'">netcoreapp3.0;net30;net35;net40;net45;net472</TargetFrameworks>
	<TargetFrameworks Condition="'$(MSBuildRuntimeType)'=='Core'">netcoreapp3.0;net40;net45;net472</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  
    <PropertyGroup>
    <FrameworkPathOverride Condition="$(TargetFramework.StartsWith('net3'))">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
  </PropertyGroup>
</Project>
<!-- Console project -->
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWpf>true</UseWpf>
    <!--<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1096;NETSDK1105;NETSDK1107</MSBuildWarningsAsMessages>-->
  </PropertyGroup>
</Project>

@drewnoakes
Copy link
Member

Would it be in scope to warn if property <UseWinForms> is defined? I'm sure lots of people would get tripped up on that.

@vatsan-madhavan
Copy link
Member Author

vatsan-madhavan commented Jun 24, 2019

Would it be in scope to warn if property <UseWinForms> is defined? I'm sure lots of people would get tripped up on that.

@drewnoakes, Are you suggesting that we should warn if <UseWinForms> is defined - which is an incorrect variant of UseWindowsForms? If this is what you have in mind, would you please open an issue and we can address this another PR?

We would need to add another warning string in the sdk - so we can't tag this change along here.

/cc @merriemcgaw

@RussKie
Copy link
Member

RussKie commented Jun 24, 2019

if <UseWinForms> is defined - which is an incorrect variant of UseWindowsForms

I'd think UseWinForms would be a better (if not correct) setting to use. I speculate here, but based on my experience "WinForms" is significantly more recognisable than "Windows Forms"

@drewnoakes
Copy link
Member

@vatsan-madhavan yes that's what I meant. Thanks for creating the issue.

@RussKie I agree (I filed issues against the new project dialog to make sure "winforms" actually returned any results) but in code the full name "WindowsForms" is used throughout. This is why I think an additional warning here would help a non-trivial number of people succeed here, especially since the current design of the project file around enable winforms/wpf is so difficult for us on the project system team to tool that customers are likely to need to write this XML by hand from memory.

@RussKie
Copy link
Member

RussKie commented Jun 25, 2019

Thank you for clarifications.

I'd spin it from a customer perspective - how we call it in our codebase is an internal detail and immaterial outside the codebase.
What would make the most sense to our consumers?

@dsplaisted
Copy link
Member

It's not about internal details of the code base. The namespace and assembly name is System.Windows.Forms, not something like System.WinForms. That is visible to customers. Project templates in VS, documentation, etc. all say Windows Forms instead of WinForms.

@stevenbrix
Copy link
Contributor

It's not about internal details of the code base. The namespace and assembly name is System.Windows.Forms, not something like System.WinForms. That is visible to customers. Project templates in VS, documentation, etc. all say Windows Forms instead of WinForms.

Right, but no one calls WPF by it's actual name - Windows Presentation Foundation. Developers are lazy and don't want to type more then they have to. They are also opinionated though, and no answer is really more correct than the other one. As a broad generalization of our kind, I think brevity is a close second behind readability/understanding. Obviously something like <UseWF> would be a bad idea because it's not immediately clear what "WF" is. Likewise, it would be equally bad to have <UseWindowsPresentationFoundation> because it doesn't help the user to understand its purpose anymore than <UseWPF> does.

I do agree with your sentiment that everything should be consistent! The command to create a new WinForms app is dotnet new winforms, but in VS you create a new "Windows Forms App (.NET Core)":
image

Personally, I think most people are comfortable and familiar with the term "WinForms" and we should go with this everywhere. This would also make the VS experience more like WPF and say "WinForms App (.NET Core)" and then in the description say the actual name. But this is also just my opinion

image

@dsplaisted
Copy link
Member

Good point about dotnet new winforms. It looks like we weren't consistent there.

@vatsan-madhavan
Copy link
Member Author

Good point about dotnet new winforms. It looks like we weren't consistent there.

please don't change this to dotnet new windowsforms /cc @merriemcgaw

@OliaG
Copy link
Member

OliaG commented Jun 25, 2019

I agree that the template dotnet new winforms should remain the same.

My personal preference would be in the project file as well since it is consistent with , clear (everyone knows what is WinForms, WindowsForms doesn't add any value), brief (users don't need to type more) and I'd also guesstimate the name "WinForms" is used more often than "Windows Forms". I'd make the correct property and prompt users if they are using . That being said I realize this would break existing WinForms Core apps, but if we want to make this change - the preview is the right time to do so.

@merriemcgaw, what do you think?

@vatsan-madhavan
Copy link
Member Author

...and I'd also guesstimate the name "WinForms" is used more often than "Windows Forms". I'd make the correct property...
the preview is the right time to do so.

We are locking down tomorrow noon for preview 7.

A change like this requires coordinated changes in dotnet/sdk and dotnet/wpf. I recommend that we pursue an approach that augments the existing design by recognizing WinForms as a synonym for WindowsForms (assuming we want to pursue a change at all - I'll defer to the WinForms team for this decision). We can pursue such a change now or in P8 (because it would be a non-breaking change).

@davkean
Copy link
Member

davkean commented Jun 26, 2019

Lots of "gut feelings" in this thread. "Windows Forms" has been consistently through documentation, training, Visual Studio UI, templates, etc since the beginning of its existence. dotnet new winforms is the odd one out here. We should not change usage from "Windows Forms" -> "WinForms" (which would have a fairly significant impact across the product) without data/interviews showing that users are confused by this, and this PR is not the right place.

@drewnoakes
Copy link
Member

Regardless of what's used, I maintain customers who hand edit their project file and use the incorrect version will appreciate guidance that they're not quite doing what's needed. Currently there's no feedback. This is not the pit of success.

@dsplaisted
Copy link
Member

Strongly agree with David, but also agree that either a warning for using the wrong property name (or possibly just allowing either property name) is a good idea.

@davkean
Copy link
Member

davkean commented Jun 26, 2019

Yep, sorry didn't mean to say that shouldn't happen RE warning. Accepting both definitions I think would be a mistake, as there are already downstream consumers of this (our capabilities are already driven off this)

@RussKie
Copy link
Member

RussKie commented Jun 26, 2019

Following your argument, we should use UseWindowsPresentationFoundation 😉

@vatsan-madhavan
Copy link
Member Author

Please move the conversation over to dotnet/winforms#1226

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
9 participants