Skip to content
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

Update C# templates with global usings #5074

Closed
Tracked by #19521
RussKie opened this issue Jun 10, 2021 · 7 comments · Fixed by #5183, #5547 or #5609
Closed
Tracked by #19521

Update C# templates with global usings #5074

RussKie opened this issue Jun 10, 2021 · 7 comments · Fixed by #5183, #5547 or #5609
Assignees
Labels
area-Templates enhancement Product code improvement that does NOT require public API changes/additions Priority:1 Work that is critical for the release, but we could probably ship without

Comments

@RussKie
Copy link
Member

RussKie commented Jun 10, 2021

We can simplify our templates with global usings and have them implemented similar to this:

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">FrameworkParameter-windows</TargetFramework>
    <TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride-windows</TargetFramework>
    <RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.WinFormsApplication1</RootNamespace>
    <LangVersion Condition="'$(langVersion)' != ''">$(ProjectLanguageVersion)</LangVersion>
    <Nullable Condition="'$(Nullable)' == 'true'">enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

+ <ItemGroup>
+   <Compile Include=".usings" />
+ </ItemGroup>

</Project>

A sample .using file:

global using System;
global using System.Collections.Generic;
global using System.Drawing;
global using System.Linq;
global using System.Threading.Tasks;
global using System.Windows.Forms;

This list of usings looks sensible, but it is up for a discussion.

Credits for this idea go to https://github.com/khalidabuhakmeh/CsharpTenFeatures.

At some point in the future when dotnet/aspnetcore#32451 settles, we could follow in their steps and bake all typical Windows Forms usings into the Windows Desktop SDK.

@RussKie RussKie added enhancement Product code improvement that does NOT require public API changes/additions area-Templates labels Jun 10, 2021
@RussKie RussKie added this to the 6.0 milestone Jun 11, 2021
@AraHaan
Copy link
Member

AraHaan commented Jun 12, 2021

I would rather name the file GlobalUsings.cs 🤔.

Bonus points: using json to store the using directives that should be global then use a source generator to generate the global usings code file. In which case I think using a json file to store the global usings is a good idea.

Also which future public SDK might come with global usings shipped with it so it would not require any preview feeds / compiler packages to use those new features then?

@RussKie
Copy link
Member Author

RussKie commented Jun 13, 2021

I would rather name the file GlobalUsings.cs 🤔.

Why?

Bonus points: using json to store the using directives that should be global then use a source generator to generate the global usings code file. In which case I think using a json file to store the global usings is a good idea.

Why? And why do we need source generators here?

@AraHaan
Copy link
Member

AraHaan commented Jun 13, 2021

I would rather name the file GlobalUsings.cs 🤔.

Why?

So that way the user could clearly see where the usings are.

Bonus points: using json to store the using directives that should be global then use a source generator to generate the global usings code file. In which case I think using a json file to store the global usings is a good idea.

Why? And why do we need source generators here?

I just stated it as a possible option that a developer could opt into to have the global usings file get source generated for them based on a json file to define which global users it should contain.

@RussKie RussKie added the ⛔ blocked Blocked by external dependencies label Jul 1, 2021
@RussKie

This comment has been minimized.

@ghost ghost added the 🚧 work in progress Work that is current in progress label Jul 1, 2021
@DamianEdwards
Copy link
Member

@RussKie the SDK feature was just merged. The epic has been updated with details of which namespaces are imported by default by the various SDKs. Please add the details for WinForms at your convenience.

@RussKie RussKie self-assigned this Jul 9, 2021
@RussKie RussKie removed the ⛔ blocked Blocked by external dependencies label Jul 9, 2021
@ghost ghost removed this from the 6.0 milestone Jul 9, 2021
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Jul 9, 2021
@RussKie RussKie reopened this Jul 23, 2021
@RussKie RussKie assigned dreddy-work and unassigned RussKie Aug 9, 2021
@RussKie
Copy link
Member Author

RussKie commented Aug 9, 2021

Refer to dotnet/sdk#19521 for new directions.

@RussKie RussKie added this to the 6.0 rc1 milestone Aug 9, 2021
@RussKie RussKie added the Priority:1 Work that is critical for the release, but we could probably ship without label Aug 9, 2021
RussKie added a commit to RussKie/winforms that referenced this issue Aug 16, 2021
@ghost ghost added the 🚧 work in progress Work that is current in progress label Aug 16, 2021
@DamianEdwards
Copy link
Member

@RussKie are you planning to bring this change through ASK mode for rc.1?

@dreddy-work dreddy-work modified the milestones: 6.0 rc1, 6.0 rc2 Aug 20, 2021
@ghost ghost removed this from the 6.0 rc2 milestone Aug 30, 2021
RussKie pushed a commit to RussKie/winforms that referenced this issue Aug 31, 2021
@ghost ghost removed the 🚧 work in progress Work that is current in progress label Sep 1, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Templates enhancement Product code improvement that does NOT require public API changes/additions Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
4 participants