winforms icon indicating copy to clipboard operation
winforms copied to clipboard

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

Open davkean opened this issue 6 years ago • 6 comments

  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Have you experienced this same bug with .NET Framework?: Yes/No

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>

davkean avatar Aug 22 '19 14:08 davkean

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.

Berrysoft avatar Sep 24 '19 14:09 Berrysoft

@KlausLoeffelmann do you have thoughts on this one?

merriemcgaw avatar Sep 08 '20 23:09 merriemcgaw

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

KlausLoeffelmann avatar Sep 09 '20 06:09 KlausLoeffelmann

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

KlausLoeffelmann avatar Dec 16 '20 22:12 KlausLoeffelmann

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.

weltkante avatar Dec 16 '20 23:12 weltkante

@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!

KlausLoeffelmann avatar Dec 17 '20 00:12 KlausLoeffelmann

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

JeremyKuhne avatar Aug 15 '23 23:08 JeremyKuhne

Yes.

KlausLoeffelmann avatar Aug 15 '23 23:08 KlausLoeffelmann