Skip to content

Update C# templates with global usings #5074

@RussKie

Description

@RussKie

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.

Metadata

Metadata

Assignees

Labels

area-TemplatesenhancementProduct code improvement that does NOT require public API changes/additionspriority-1Work that is critical for the release, but we could probably ship without

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions