dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.4k stars 977 forks source link

Windows Forms templates should carry proj.user with SubType already set #3510

Closed davkean closed 4 years ago

davkean commented 4 years ago

Problem description:

To detect that a Forms is openable by the designer (and gets the icon), Roslyn asynchronously reads the attributes of a type's base types and pushes a "SubType" if the right attribute is present to the project system. Which in turn, causes the designer paths to light up.

This is a slow and asynchronous process and cannot be blocked on, and causes additional evaluations and design-time builds to kicked off after Roslyn sets the subtype.

To side step this whole process, and improve the speed for opening the designer and to reduce the number of design-builds that are needed for File -> New, the templates should carry this information and have the project system automatically recognize that this project contains a designable file.

To do that, carry a UTF8-with BOM file alongside the project called "[Project].csproj.user"

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Compile Update="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
  </ItemGroup>
</Project>
weltkante commented 4 years ago

Does this really make any difference? VS ignores *.csproj.user files by default when checking in to source control (at least for GIT and TFS) - so this only marginally improves performance when creating a brand new project, checking out from source control would not benefit, and in my experience this is the much more common operation. Classic projects stored this setting in the project file so they didn't have this problem.

Can't this be stored somewhere that is persisted properly? Its not really a user setting ...

davkean commented 4 years ago

Yes it makes a difference in this scenario, hence why I filed this.

weltkante commented 4 years ago

I'd argue a solution that works more than once would be better. This suggestion just works at project creation and never again for anyone else who starts working on the project. So it makes a difference for one person one time, not really a difference in the long term.

(I'm not going to keep arguing, just my opinion here, to suggest considering alternatives.)

davkean commented 4 years ago

Legacy does the same thing with its templates (carries subtype), so regardless of whether there is a better solution to putting subtype in the user file, we are still going to be carrying it in the template.

Zheng-Li01 commented 4 years ago

Verified the issue with latest .NET 5.0 SDK, the Form1.cs[Design] page is opened directly and have the below code section generated in the .csproj.user file. see below GIF. however noticed that the spending time to open Form1.cs[Design] is still longer than Framework project. Code section: `<?xml version="1.0" encoding="utf-8"?>

Form ` ![UpdateCoreIssue](https://user-images.githubusercontent.com/38325459/87495140-39be2700-c683-11ea-8163-c6e62bea2c89.gif)
davkean commented 4 years ago

It takes longer because it performs a NuGet restore, which legacy does not.