dotnet / winforms

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

Windows Forms VB project template should have implicit imports instead of explict #1678

Open davkean opened 5 years ago

davkean commented 5 years ago

Problem description:

Unlike the VB Console App and WPF App, the Windows Forms template has some (but not all) "explicit" imports. These should be moved to the Windows Desktop SDK similar to the rest of the imports to keep the project file small by default.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RootNamespace>WindowsFormsApp3</RootNamespace>
    <StartupObject>WindowsFormsApp3.Form1</StartupObject>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup>
    <Import Include="System.Data" /> <!--- These three should be implicit and in WindowsDesktop SDK -->
    <Import Include="System.Drawing" />
    <Import Include="System.Windows.Forms" />
  </ItemGroup>

</Project>
Berrysoft commented 5 years ago

There are also imports in the WPF template.

And the implicit imports for Visual Basic Console App is in the Microsoft.NET.Sdk.VisualBasic.targets.

I don't think it'll be a small change to move the imports to SDK.

merriemcgaw commented 4 years ago

@KlausLoeffelmann do you have thoughts on this one?

KlausLoeffelmann commented 4 years ago

@KathleenDollard, this is also something we need to talk about.

KlausLoeffelmann commented 3 years ago

We'll further discuss this when we'll add the HighDpiSetting to Project System.

weltkante commented 3 years ago

Whats there to discuss? As far as I can tell these imports are already implicitly added, I just removed them from the project file and everything still compiles even if types from these assemblies are used. I don't think this is language-specific, C# projects don't add these imports either, so looking in the language-specific targets is probably the wrong place to look.

(Note that if you remove the imports then Application.Designer.HighDpi.vb fails to compile because its missing an Imports System.Windows.Forms statement and not qualifying HighDpiMode fully. IMHO its bad practice to not specify the namespace imports your designer code relys on, since you never know what the user has in the project file anyways)

[edit] nevermind I mixed up <Reference> and <Import> declarations. These are adding default-imports which only exists in VB and not in C#. In that case I agree this depends on the project system and probably needs further discussion how to handle.

I'd still argue the Designer file should be written to be independent of any (possibly absent) default imports.

KlausLoeffelmann commented 3 years ago

@weltkante: I want to get rid of Application.Designer.HeighDpi.vb altogether for the .NET 6 templates. The remark was more of a reminder to all of us that we need to address a few issues around this come the new year. In this context: Thanks so much again for all your support, erholsame Feiertage und nen guten Rutsch ins neue Jahr!

JeremyKuhne commented 1 year ago

@KlausLoeffelmann is this something we still plan to do? I've moved to .NET 9 for now.

KlausLoeffelmann commented 1 year ago

Yes.

KlausLoeffelmann commented 2 months ago

Moving to .NET 10.