From 5a933143f82e9324650a6581f5ed600fb9697414 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Wed, 25 Aug 2021 17:01:00 +1000 Subject: [PATCH] Update templates to use `ApplicationConfiguration.Initialize()` Relates to #5035 Relates to #5071 --- .../.template.config/template.json | 25 ++++++++++++++++--- .../Program.boilerplate.cs | 23 +++++++++++++++++ .../WinFormsApplication-CSharp/Program.cs | 4 +-- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.boilerplate.cs diff --git a/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/.template.config/template.json b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/.template.config/template.json index d6f9721afad..68ca5548aa2 100644 --- a/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/.template.config/template.json +++ b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/.template.config/template.json @@ -53,6 +53,10 @@ "type": "computed", "value": "(Framework == \"netcoreapp3.1\")" }, + "UseApplicationBoilerplate": { + "type": "computed", + "value": "(Framework == \"net5.0\")" + }, "langVersion": { "type": "parameter", "datatype": "text", @@ -94,16 +98,29 @@ { "condition": "(UseWindowsDesktopSdk)", "exclude": [ - "Company.WinFormsApplication1.csproj" + "Company.WinFormsApplication1.csproj", + "Program.cs" + ], + "rename": { + "Company.WinFormsApplication3x1.csproj": "Company.WinFormsApplication1.csproj", + "Program.boilerplate.cs": "Program.cs" + } + }, + { + "condition": "(!UseWindowsDesktopSdk && UseApplicationBoilerplate)", + "exclude": [ + "Company.WinFormsApplication3x1.csproj", + "Program.cs" ], "rename": { - "Company.WinFormsApplication3x1.csproj": "Company.WinFormsApplication1.csproj" + "Program.boilerplate.cs": "Program.cs" } }, { - "condition": "(!UseWindowsDesktopSdk)", + "condition": "(!UseWindowsDesktopSdk && !UseApplicationBoilerplate)", "exclude": [ - "Company.WinFormsApplication3x1.csproj" + "Company.WinFormsApplication3x1.csproj", + "Program.boilerplate.cs" ] } ] diff --git a/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.boilerplate.cs b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.boilerplate.cs new file mode 100644 index 00000000000..f456f2c592b --- /dev/null +++ b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.boilerplate.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Company.WinFormsApplication1 +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.cs b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.cs index f456f2c592b..026f8234c1d 100644 --- a/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.cs +++ b/pkg/Microsoft.Dotnet.WinForms.ProjectTemplates/content/WinFormsApplication-CSharp/Program.cs @@ -14,9 +14,7 @@ static class Program [STAThread] static void Main() { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); + ApplicationConfiguration.Initialize(); Application.Run(new Form1()); } }