From 1fbec2789b3ba7603deb9cc0fb8acd852d5e6f4d Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 18 Oct 2021 14:58:55 -0700 Subject: [PATCH 01/15] Implement .NET 6 features for templates. Implicit/Global Usings, Scoped Namespaces, & more --- .../src/templates/maui-blazor/App.xaml.cs | 18 ++++----- .../maui-blazor/Data/WeatherForecast.cs | 16 ++------ .../Data/WeatherForecastService.cs | 30 ++++++-------- .../src/templates/maui-blazor/GlobalUsings.cs | 7 ++++ .../templates/maui-blazor/MainPage.xaml.cs | 12 ++---- .../templates/maui-blazor/MauiApp.1.csproj | 1 + .../src/templates/maui-blazor/MauiProgram.cs | 38 ++++++++---------- .../Platforms/Android/MainActivity.cs | 22 +++++++---- .../Platforms/Android/MainApplication.cs | 25 +++++------- .../Platforms/MacCatalyst/AppDelegate.cs | 15 +++---- .../Platforms/MacCatalyst/Program.cs | 17 ++++---- .../maui-blazor/Platforms/Windows/App.xaml.cs | 39 +++++++++---------- .../maui-blazor/Platforms/iOS/AppDelegate.cs | 15 +++---- .../maui-blazor/Platforms/iOS/Program.cs | 20 ++++------ .../src/templates/maui-lib/Class1.cs | 11 ++---- .../src/templates/maui-lib/MauiLib1.csproj | 1 + .../Platforms/Android/PlatformClass1.cs | 11 ++---- .../Platforms/MacCatalyst/PlatformClass1.cs | 11 ++---- .../Platforms/Windows/PlatformClass1.cs | 11 ++---- .../maui-lib/Platforms/iOS/PlatformClass1.cs | 11 ++---- .../src/templates/maui-mobile/App.xaml.cs | 18 ++++----- .../src/templates/maui-mobile/GlobalUsings.cs | 7 ++++ .../templates/maui-mobile/MainPage.xaml.cs | 30 +++++++------- .../templates/maui-mobile/MauiApp.1.csproj | 8 ++-- .../src/templates/maui-mobile/MauiProgram.cs | 30 ++++++-------- .../Platforms/Android/MainActivity.cs | 22 +++++++---- .../Platforms/Android/MainApplication.cs | 25 +++++------- .../Platforms/MacCatalyst/AppDelegate.cs | 15 +++---- .../Platforms/MacCatalyst/Program.cs | 19 ++++----- .../maui-mobile/Platforms/Windows/App.xaml.cs | 39 +++++++++---------- .../maui-mobile/Platforms/iOS/AppDelegate.cs | 15 +++---- .../maui-mobile/Platforms/iOS/Program.cs | 19 ++++----- 32 files changed, 250 insertions(+), 328 deletions(-) create mode 100644 src/Templates/src/templates/maui-blazor/GlobalUsings.cs create mode 100644 src/Templates/src/templates/maui-mobile/GlobalUsings.cs diff --git a/src/Templates/src/templates/maui-blazor/App.xaml.cs b/src/Templates/src/templates/maui-blazor/App.xaml.cs index 147ef09ada30..8da180971b75 100644 --- a/src/Templates/src/templates/maui-blazor/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/App.xaml.cs @@ -1,17 +1,13 @@ -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; -using Application = Microsoft.Maui.Controls.Application; +using Application = Microsoft.Maui.Controls.Application; -namespace MauiApp._1 +namespace MauiApp._1; + +public partial class App : Application { - public partial class App : Application + public App() { - public App() - { - InitializeComponent(); + InitializeComponent(); - MainPage = new MainPage(); - } + MainPage = new MainPage(); } } diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs index 905541d8048d..f3559af24242 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs @@ -1,15 +1,7 @@ -using System; +namespace MauiApp._1.Data; -namespace MauiApp._1.Data +public record WeatherForecast(DateTime Date, int TemperatureC, string Summary) { - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); } + diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs index a1c36686a7bf..7bb8b58d388a 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs @@ -1,24 +1,16 @@ -using System; -using System.Linq; -using System.Threading.Tasks; +namespace MauiApp._1.Data; -namespace MauiApp._1.Data +public class WeatherForecastService { - public class WeatherForecastService + private static readonly string[] Summaries = new[] { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; - public Task GetForecastAsync(DateTime startDate) - { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } - } + public Task GetForecastAsync(DateTime startDate) => + Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast( + startDate.AddDays(index), + Random.Shared.Next(-20, 55), + Summaries[Random.Shared.Next(Summaries.Length)])).ToArray()); } + diff --git a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs new file mode 100644 index 000000000000..8598e47d9c42 --- /dev/null +++ b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs @@ -0,0 +1,7 @@ +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Maui; +global using Microsoft.Maui.Controls; +global using Microsoft.Maui.Controls.Xaml; +global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Essentials; +global using Microsoft.Maui.Hosting; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs b/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs index 0dbdbc7f3250..5bf5834c5f0c 100644 --- a/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/MainPage.xaml.cs @@ -1,13 +1,9 @@ -using System; -using Microsoft.Maui.Controls; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class MainPage : ContentPage { - public partial class MainPage : ContentPage + public MainPage() { - public MainPage() - { - InitializeComponent(); - } + InitializeComponent(); } } diff --git a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj index 08ea4b7dba36..03edaec6394c 100644 --- a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj @@ -9,6 +9,7 @@ true true false + enable MauiApp.1 diff --git a/src/Templates/src/templates/maui-blazor/MauiProgram.cs b/src/Templates/src/templates/maui-blazor/MauiProgram.cs index 6b3c8a54dcfd..6d5379b282e8 100644 --- a/src/Templates/src/templates/maui-blazor/MauiProgram.cs +++ b/src/Templates/src/templates/maui-blazor/MauiProgram.cs @@ -1,30 +1,24 @@ using Microsoft.AspNetCore.Components.WebView.Maui; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Hosting; using MauiApp._1.Data; -namespace MauiApp._1 +namespace MauiApp._1; + +public static class MauiProgram { - public static class MauiProgram + public static MauiApp CreateMauiApp() { - public static MauiApp CreateMauiApp() - { - var builder = MauiApp.CreateBuilder(); - builder - .RegisterBlazorMauiWebView() - .UseMauiApp() - .ConfigureFonts(fonts => - { - fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); - }); + var builder = MauiApp.CreateBuilder(); + builder + .RegisterBlazorMauiWebView() + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + }); - builder.Services.AddBlazorWebView(); - builder.Services.AddSingleton(); + builder.Services.AddBlazorWebView(); + builder.Services.AddSingleton(); - return builder.Build(); - } + return builder.Build(); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs index 7f12c68d473f..ef8985c5f6bc 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs @@ -1,11 +1,19 @@ -using Android.App; -using Android.Content.PM; -using Microsoft.Maui; +using Android.Content.PM; -namespace MauiApp._1 +namespace MauiApp._1; + +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] +public class MainActivity : MauiAppCompatActivity { - [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] - public class MainActivity : MauiAppCompatActivity + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + Platform.Init(this, savedInstanceState); + } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { + Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); + + base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs index 4fe7e7a9d8e5..cc57a5ca4692 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs @@ -1,19 +1,14 @@ -using System; -using Android.App; -using Android.Runtime; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +using Android.Runtime; -namespace MauiApp._1 +namespace MauiApp._1; + +[Application] +public class MainApplication : MauiApplication { - [Application] - public class MainApplication : MauiApplication + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } - - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } -} \ No newline at end of file + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs index 1c07e0e4a78f..33e183c0833b 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs @@ -1,12 +1,7 @@ -using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs index c9227639e685..8b50246ee003 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs @@ -1,15 +1,12 @@ -using UIKit; +namespace MauiApp._1; -namespace MauiApp._1 +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } } \ No newline at end of file diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs b/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs index 5e0e454ec7d3..784c92201fe2 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Windows/App.xaml.cs @@ -1,34 +1,31 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.UI.Xaml; -using Windows.ApplicationModel; +using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace MauiApp._1.WinUI +namespace MauiApp._1.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication { /// - /// Provides application-specific behavior to supplement the default Application class. + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). /// - public partial class App : MauiWinUIApplication + public App() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - } + this.InitializeComponent(); + } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - protected override void OnLaunched(LaunchActivatedEventArgs args) - { - base.OnLaunched(args); + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + base.OnLaunched(args); - Microsoft.Maui.Essentials.Platform.OnLaunched(args); - } + Platform.OnLaunched(args); } } + diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs index 1c07e0e4a78f..33e183c0833b 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs @@ -1,12 +1,7 @@ -using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs index c9227639e685..b6c946bf320c 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs @@ -1,15 +1,11 @@ -using UIKit; - -namespace MauiApp._1 +namespace MauiApp._1; +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Class1.cs b/src/Templates/src/templates/maui-lib/Class1.cs index af03b9692d6a..90d85dc14ffb 100644 --- a/src/Templates/src/templates/maui-lib/Class1.cs +++ b/src/Templates/src/templates/maui-lib/Class1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is included in all platforms. +public class Class1 { - // All the code in this file is included in all platforms. - public class Class1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/MauiLib1.csproj b/src/Templates/src/templates/maui-lib/MauiLib1.csproj index faac72183cda..9a8d627e3708 100644 --- a/src/Templates/src/templates/maui-lib/MauiLib1.csproj +++ b/src/Templates/src/templates/maui-lib/MauiLib1.csproj @@ -7,6 +7,7 @@ MauiLib1 true true + enable 14.2 14.0 diff --git a/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs index 8247e4af1424..ded3cc02ff58 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/Android/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Android. +public class PlatformClass1 { - // All the code in this file is only included on Android. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs index 404be11489fd..3897b9cd402b 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/MacCatalyst/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Mac Catalyst. +public class PlatformClass1 { - // All the code in this file is only included on Mac Catalyst. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs index feb45db71f3f..0a25465d0855 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/Windows/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on Windows. +public class PlatformClass1 { - // All the code in this file is only included on Windows. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs b/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs index b48f3106af42..df8b1d52b427 100644 --- a/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs +++ b/src/Templates/src/templates/maui-lib/Platforms/iOS/PlatformClass1.cs @@ -1,9 +1,6 @@ -using System; +namespace MauiLib1; -namespace MauiLib1 +// All the code in this file is only included on iOS. +public class PlatformClass1 { - // All the code in this file is only included on iOS. - public class PlatformClass1 - { - } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/App.xaml.cs b/src/Templates/src/templates/maui-mobile/App.xaml.cs index 147ef09ada30..8da180971b75 100644 --- a/src/Templates/src/templates/maui-mobile/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/App.xaml.cs @@ -1,17 +1,13 @@ -using Microsoft.Maui; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; -using Application = Microsoft.Maui.Controls.Application; +using Application = Microsoft.Maui.Controls.Application; -namespace MauiApp._1 +namespace MauiApp._1; + +public partial class App : Application { - public partial class App : Application + public App() { - public App() - { - InitializeComponent(); + InitializeComponent(); - MainPage = new MainPage(); - } + MainPage = new MainPage(); } } diff --git a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs new file mode 100644 index 000000000000..8598e47d9c42 --- /dev/null +++ b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs @@ -0,0 +1,7 @@ +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Maui; +global using Microsoft.Maui.Controls; +global using Microsoft.Maui.Controls.Xaml; +global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Essentials; +global using Microsoft.Maui.Hosting; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs b/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs index 70ce790edc5b..5825d4b101af 100644 --- a/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/MainPage.xaml.cs @@ -1,24 +1,20 @@ -using System; -using Microsoft.Maui.Controls; -using Microsoft.Maui.Essentials; +namespace MauiApp._1; -namespace MauiApp._1 +public partial class MainPage : ContentPage { - public partial class MainPage : ContentPage - { - int count = 0; + int count = 0; - public MainPage() - { - InitializeComponent(); - } + public MainPage() + { + InitializeComponent(); + } - private void OnCounterClicked(object sender, EventArgs e) - { - count++; - CounterLabel.Text = $"Current count: {count}"; + private void OnCounterClicked(object sender, EventArgs e) + { + count++; + CounterLabel.Text = $"Current count: {count}"; - SemanticScreenReader.Announce(CounterLabel.Text); - } + SemanticScreenReader.Announce(CounterLabel.Text); } } + diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index bb7e69b33b0c..69eac3bc8a17 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -8,7 +8,8 @@ true true true - + enable + MauiApp.1 @@ -29,10 +30,7 @@ - + diff --git a/src/Templates/src/templates/maui-mobile/MauiProgram.cs b/src/Templates/src/templates/maui-mobile/MauiProgram.cs index 2dc6c5c0edf7..a83edefa6c15 100644 --- a/src/Templates/src/templates/maui-mobile/MauiProgram.cs +++ b/src/Templates/src/templates/maui-mobile/MauiProgram.cs @@ -1,23 +1,17 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.Maui.Controls.Compatibility; -using Microsoft.Maui.Controls.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +public static class MauiProgram { - public static class MauiProgram + public static MauiApp CreateMauiApp() { - public static MauiApp CreateMauiApp() - { - var builder = MauiApp.CreateBuilder(); - builder - .UseMauiApp() - .ConfigureFonts(fonts => - { - fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); - }); + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + }); - return builder.Build(); - } + return builder.Build(); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs index 7f12c68d473f..ef8985c5f6bc 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs @@ -1,11 +1,19 @@ -using Android.App; -using Android.Content.PM; -using Microsoft.Maui; +using Android.Content.PM; -namespace MauiApp._1 +namespace MauiApp._1; + +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] +public class MainActivity : MauiAppCompatActivity { - [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] - public class MainActivity : MauiAppCompatActivity + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + Platform.Init(this, savedInstanceState); + } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { + Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); + + base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs index 4fe7e7a9d8e5..cc57a5ca4692 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs @@ -1,19 +1,14 @@ -using System; -using Android.App; -using Android.Runtime; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +using Android.Runtime; -namespace MauiApp._1 +namespace MauiApp._1; + +[Application] +public class MainApplication : MauiApplication { - [Application] - public class MainApplication : MauiApplication + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } - - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } -} \ No newline at end of file + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs index 1c07e0e4a78f..33e183c0833b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs @@ -1,12 +1,7 @@ -using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs index c9227639e685..fab6c260ffef 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs @@ -1,15 +1,12 @@ -using UIKit; +namespace MauiApp._1; -namespace MauiApp._1 +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs index 5e0e454ec7d3..b15bcfe53777 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs @@ -1,34 +1,31 @@ -using Microsoft.Maui; -using Microsoft.Maui.Hosting; -using Microsoft.UI.Xaml; -using Windows.ApplicationModel; +using Microsoft.UI.Xaml; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. -namespace MauiApp._1.WinUI +namespace MauiApp._1.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication { /// - /// Provides application-specific behavior to supplement the default Application class. + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). /// - public partial class App : MauiWinUIApplication + public App() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - } + this.InitializeComponent(); + } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - protected override void OnLaunched(LaunchActivatedEventArgs args) - { - base.OnLaunched(args); + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + base.OnLaunched(args); - Microsoft.Maui.Essentials.Platform.OnLaunched(args); - } + Microsoft.Maui.Essentials.Platform.OnLaunched(args); } } + diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs index 1c07e0e4a78f..33e183c0833b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs @@ -1,12 +1,7 @@ -using Foundation; -using Microsoft.Maui; -using Microsoft.Maui.Hosting; +namespace MauiApp._1; -namespace MauiApp._1 +[Register("AppDelegate")] +public class AppDelegate : MauiUIApplicationDelegate { - [Register("AppDelegate")] - public class AppDelegate : MauiUIApplicationDelegate - { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); - } -} \ No newline at end of file + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs index c9227639e685..fab6c260ffef 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs @@ -1,15 +1,12 @@ -using UIKit; +namespace MauiApp._1; -namespace MauiApp._1 +public class Program { - public class Program + // This is the main entry point of the application. + static void Main(string[] args) { - // This is the main entry point of the application. - static void Main(string[] args) - { - // if you want to use a different Application Delegate class from "AppDelegate" - // you can specify it here. - UIApplication.Main(args, null, typeof(AppDelegate)); - } + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); } -} \ No newline at end of file +} From 74c8735f7fed7a6afc4cdc75faa525f234125559 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 18 Oct 2021 15:54:51 -0700 Subject: [PATCH 02/15] Updates based on feedback --- .../maui-blazor/Data/WeatherForecastService.cs | 15 +++++++++++---- .../src/templates/maui-blazor/MauiApp.1.csproj | 2 +- .../src/templates/maui-lib/MauiLib1.csproj | 2 +- .../src/templates/maui-mobile/MauiApp.1.csproj | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs index 7bb8b58d388a..aff16a40d72c 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs @@ -7,10 +7,17 @@ public class WeatherForecastService "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - public Task GetForecastAsync(DateTime startDate) => - Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast( - startDate.AddDays(index), + public Task GetForecastAsync(DateTime startDate) + { + var forecasts = Enumerable.Range(1, 5).Select(index => + new WeatherForecast + ( + DateTime.Now.AddDays(index), Random.Shared.Next(-20, 55), - Summaries[Random.Shared.Next(Summaries.Length)])).ToArray()); + summaries[Random.Shared.Next(summaries.Length)] + )) + .ToArray(); + return forecasts; + } } diff --git a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj index 03edaec6394c..45b25069537f 100644 --- a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj @@ -9,7 +9,7 @@ true true false - enable + enable MauiApp.1 diff --git a/src/Templates/src/templates/maui-lib/MauiLib1.csproj b/src/Templates/src/templates/maui-lib/MauiLib1.csproj index 9a8d627e3708..a923ab2d67a9 100644 --- a/src/Templates/src/templates/maui-lib/MauiLib1.csproj +++ b/src/Templates/src/templates/maui-lib/MauiLib1.csproj @@ -7,7 +7,7 @@ MauiLib1 true true - enable + enable 14.2 14.0 diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index 69eac3bc8a17..41c1a1005ded 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -8,7 +8,7 @@ true true true - enable + enable MauiApp.1 From 375df93dfe57396f0ae75016c623526db482055b Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 18 Oct 2021 15:56:43 -0700 Subject: [PATCH 03/15] Forecast --- .../src/templates/maui-blazor/Data/WeatherForecastService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs index aff16a40d72c..2dd0ba33346d 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs @@ -17,7 +17,8 @@ public Task GetForecastAsync(DateTime startDate) summaries[Random.Shared.Next(summaries.Length)] )) .ToArray(); - return forecasts; + + return Task.FromResult(forecasts); } } From 1a469de105c2031155f1cf3298c6b52b11fa8e9a Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 18 Oct 2021 16:00:25 -0700 Subject: [PATCH 04/15] Sort usings --- src/Templates/src/templates/maui-blazor/GlobalUsings.cs | 2 +- src/Templates/src/templates/maui-mobile/GlobalUsings.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs index 8598e47d9c42..f30be2090013 100644 --- a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs +++ b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs @@ -1,7 +1,7 @@ global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Maui; global using Microsoft.Maui.Controls; -global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Essentials; global using Microsoft.Maui.Hosting; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs index 8598e47d9c42..f30be2090013 100644 --- a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs +++ b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs @@ -1,7 +1,7 @@ global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Maui; global using Microsoft.Maui.Controls; -global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Controls.Hosting; +global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Essentials; global using Microsoft.Maui.Hosting; \ No newline at end of file From 2392b300e31891eb84b64a3213b6795bf1d1b165 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 19 Oct 2021 10:08:29 -0700 Subject: [PATCH 05/15] revert back blazor weather stuff --- .../maui-blazor/Data/WeatherForecast.cs | 9 +++++++-- .../maui-blazor/Data/WeatherForecastService.cs | 16 ++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs index f3559af24242..ae62090cfc65 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecast.cs @@ -1,7 +1,12 @@ namespace MauiApp._1.Data; -public record WeatherForecast(DateTime Date, int TemperatureC, string Summary) +public class WeatherForecast { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); -} + public string Summary { get; set; } +} diff --git a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs index 2dd0ba33346d..60b37c417636 100644 --- a/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs +++ b/src/Templates/src/templates/maui-blazor/Data/WeatherForecastService.cs @@ -9,16 +9,12 @@ public class WeatherForecastService public Task GetForecastAsync(DateTime startDate) { - var forecasts = Enumerable.Range(1, 5).Select(index => - new WeatherForecast - ( - DateTime.Now.AddDays(index), - Random.Shared.Next(-20, 55), - summaries[Random.Shared.Next(summaries.Length)] - )) - .ToArray(); - - return Task.FromResult(forecasts); + return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = startDate.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }).ToArray()); } } From cf1ed40915ac4eeef56a31a371595ac581580a95 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 19 Oct 2021 10:17:03 -0700 Subject: [PATCH 06/15] More changes based on feedback --- src/Templates/src/templates/maui-blazor/App.xaml.cs | 4 ++-- .../templates/maui-blazor/Platforms/Android/MainActivity.cs | 1 + src/Templates/src/templates/maui-mobile/App.xaml.cs | 4 ++-- .../templates/maui-mobile/Platforms/Android/MainActivity.cs | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/App.xaml.cs b/src/Templates/src/templates/maui-blazor/App.xaml.cs index 8da180971b75..b16596eb00f4 100644 --- a/src/Templates/src/templates/maui-blazor/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/App.xaml.cs @@ -1,8 +1,8 @@ -using Application = Microsoft.Maui.Controls.Application; +using MauiApplication = Microsoft.Maui.Controls.Application; namespace MauiApp._1; -public partial class App : Application +public partial class App : MauiApplication { public App() { diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs index ef8985c5f6bc..40856f5e1615 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs @@ -10,6 +10,7 @@ protected override void OnCreate(Bundle savedInstanceState) base.OnCreate(savedInstanceState); Platform.Init(this, savedInstanceState); } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); diff --git a/src/Templates/src/templates/maui-mobile/App.xaml.cs b/src/Templates/src/templates/maui-mobile/App.xaml.cs index 8da180971b75..b16596eb00f4 100644 --- a/src/Templates/src/templates/maui-mobile/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/App.xaml.cs @@ -1,8 +1,8 @@ -using Application = Microsoft.Maui.Controls.Application; +using MauiApplication = Microsoft.Maui.Controls.Application; namespace MauiApp._1; -public partial class App : Application +public partial class App : MauiApplication { public App() { diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs index ef8985c5f6bc..40856f5e1615 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs @@ -10,6 +10,7 @@ protected override void OnCreate(Bundle savedInstanceState) base.OnCreate(savedInstanceState); Platform.Init(this, savedInstanceState); } + public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); From 7718ff3ece3e4b7ac17524754eb47450a7d3ae30 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Wed, 20 Oct 2021 13:53:44 -0700 Subject: [PATCH 07/15] Adjjust appxmanifest for tempaltes --- .../maui-blazor/Platforms/Windows/Package.appxmanifest | 4 ++-- src/Templates/src/templates/maui-lib/MauiLib1.csproj | 2 +- .../src/templates/maui-mobile/Platforms/Windows/App.xaml.cs | 2 +- .../maui-mobile/Platforms/Windows/Package.appxmanifest | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest b/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest index 93ef05c970f1..b2c6894ed355 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest +++ b/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest @@ -18,8 +18,8 @@ - - + + diff --git a/src/Templates/src/templates/maui-lib/MauiLib1.csproj b/src/Templates/src/templates/maui-lib/MauiLib1.csproj index a923ab2d67a9..465a6359230d 100644 --- a/src/Templates/src/templates/maui-lib/MauiLib1.csproj +++ b/src/Templates/src/templates/maui-lib/MauiLib1.csproj @@ -3,7 +3,7 @@ net6.0;net6.0-ios;net6.0-android;net6.0-maccatalyst $(TargetFrameworks);net6.0-windows10.0.19041 - 10.0.17763.0 + 10.0.18362.0 MauiLib1 true true diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs index b15bcfe53777..784c92201fe2 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Windows/App.xaml.cs @@ -25,7 +25,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); - Microsoft.Maui.Essentials.Platform.OnLaunched(args); + Platform.OnLaunched(args); } } diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest b/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest index 55c7c109aa14..b561fc163e4a 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest +++ b/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest @@ -18,8 +18,8 @@ - - + + From fefc64b6c22165997125754ff06f4d4205c5d3aa Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 25 Oct 2021 13:46:38 -0700 Subject: [PATCH 08/15] comment out windows again --- src/Templates/src/templates/maui-blazor/MauiApp.1.csproj | 6 +++--- src/Templates/src/templates/maui-mobile/MauiApp.1.csproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj index 45b25069537f..d05343dc2767 100644 --- a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj @@ -2,14 +2,14 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - $(TargetFrameworks);net6.0-windows10.0.19041 - Exe + + Exe MauiApp._1 true true true false - enable + enable MauiApp.1 diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index 41c1a1005ded..298216776fa9 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -2,13 +2,13 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - $(TargetFrameworks);net6.0-windows10.0.19041 - Exe + + Exe MauiApp._1 true true true - enable + enable MauiApp.1 From dac8e2a8dbbbe4d3451eb956c0d3f0a3cdf156af Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 25 Oct 2021 13:49:23 -0700 Subject: [PATCH 09/15] Update MauiApp.1.csproj --- src/Templates/src/templates/maui-mobile/MauiApp.1.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index a4b61dba835a..3546bbabb58c 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -2,13 +2,13 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - - Exe + + Exe MauiApp._1 true true true - enable + enable MauiApp.1 From 84a7e410491b599c7611afb3e1e26c7313824b3a Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 25 Oct 2021 13:49:44 -0700 Subject: [PATCH 10/15] Update MauiApp.1.csproj --- src/Templates/src/templates/maui-blazor/MauiApp.1.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj index d09bd734309c..4a56aa3e0f73 100644 --- a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj @@ -2,14 +2,14 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - - Exe + + Exe MauiApp._1 true true true false - enable + enable MauiApp.1 From 043e0c98fc918e99023d001f609d269571b89c60 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 26 Oct 2021 09:47:33 -0700 Subject: [PATCH 11/15] revert changes back --- .../maui-blazor/Platforms/Windows/Package.appxmanifest | 4 ++-- .../maui-mobile/Platforms/Windows/Package.appxmanifest | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest b/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest index b2c6894ed355..93ef05c970f1 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest +++ b/src/Templates/src/templates/maui-blazor/Platforms/Windows/Package.appxmanifest @@ -18,8 +18,8 @@ - - + + diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest b/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest index b561fc163e4a..55c7c109aa14 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest +++ b/src/Templates/src/templates/maui-mobile/Platforms/Windows/Package.appxmanifest @@ -18,8 +18,8 @@ - - + + From 2675ba816573074938808c229357bb3697835bed Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 26 Oct 2021 10:09:11 -0700 Subject: [PATCH 12/15] Changes based on conversation --- src/Templates/src/templates/maui-blazor/GlobalUsings.cs | 9 ++++++++- src/Templates/src/templates/maui-blazor/MauiApp.1.csproj | 3 +-- src/Templates/src/templates/maui-lib/MauiLib1.csproj | 1 - src/Templates/src/templates/maui-mobile/GlobalUsings.cs | 9 ++++++++- src/Templates/src/templates/maui-mobile/MauiApp.1.csproj | 3 +-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs index f30be2090013..47acf5b44b52 100644 --- a/src/Templates/src/templates/maui-blazor/GlobalUsings.cs +++ b/src/Templates/src/templates/maui-blazor/GlobalUsings.cs @@ -4,4 +4,11 @@ global using Microsoft.Maui.Controls.Hosting; global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Essentials; -global using Microsoft.Maui.Hosting; \ No newline at end of file +global using Microsoft.Maui.Hosting; +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Linq; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj index 4a56aa3e0f73..26a1d8c091da 100644 --- a/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-blazor/MauiApp.1.csproj @@ -3,13 +3,12 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - Exe + Exe MauiApp._1 true true true false - enable MauiApp.1 diff --git a/src/Templates/src/templates/maui-lib/MauiLib1.csproj b/src/Templates/src/templates/maui-lib/MauiLib1.csproj index 38d2b692b714..3cb8afeb61c9 100644 --- a/src/Templates/src/templates/maui-lib/MauiLib1.csproj +++ b/src/Templates/src/templates/maui-lib/MauiLib1.csproj @@ -6,7 +6,6 @@ MauiLib1 true true - enable 14.2 14.0 diff --git a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs index f30be2090013..47acf5b44b52 100644 --- a/src/Templates/src/templates/maui-mobile/GlobalUsings.cs +++ b/src/Templates/src/templates/maui-mobile/GlobalUsings.cs @@ -4,4 +4,11 @@ global using Microsoft.Maui.Controls.Hosting; global using Microsoft.Maui.Controls.Xaml; global using Microsoft.Maui.Essentials; -global using Microsoft.Maui.Hosting; \ No newline at end of file +global using Microsoft.Maui.Hosting; +global using System; +global using System.Collections.Generic; +global using System.IO; +global using System.Linq; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; \ No newline at end of file diff --git a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj index 3546bbabb58c..a989a0f45185 100644 --- a/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj +++ b/src/Templates/src/templates/maui-mobile/MauiApp.1.csproj @@ -3,12 +3,11 @@ net6.0-ios;net6.0-android;net6.0-maccatalyst - Exe + Exe MauiApp._1 true true true - enable MauiApp.1 From 85828eae48bdb6b7188397df94e37fd71d254802 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Tue, 26 Oct 2021 10:15:09 -0700 Subject: [PATCH 13/15] Add back usings from native platforms --- .../templates/maui-blazor/Platforms/Android/MainActivity.cs | 4 +++- .../maui-blazor/Platforms/Android/MainApplication.cs | 3 ++- .../maui-blazor/Platforms/MacCatalyst/AppDelegate.cs | 4 +++- .../templates/maui-blazor/Platforms/MacCatalyst/Program.cs | 4 +++- .../src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs | 4 +++- .../src/templates/maui-blazor/Platforms/iOS/Program.cs | 5 ++++- .../templates/maui-mobile/Platforms/Android/MainActivity.cs | 4 +++- .../maui-mobile/Platforms/Android/MainApplication.cs | 3 ++- .../maui-mobile/Platforms/MacCatalyst/AppDelegate.cs | 4 +++- .../templates/maui-mobile/Platforms/MacCatalyst/Program.cs | 4 +++- .../src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs | 4 +++- .../src/templates/maui-mobile/Platforms/iOS/Program.cs | 4 +++- 12 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs index 40856f5e1615..b189df660d25 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainActivity.cs @@ -1,4 +1,6 @@ -using Android.Content.PM; +using Android.App; +using Android.Content.PM; +using Android.OS; namespace MauiApp._1; diff --git a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs index cc57a5ca4692..83b97cfe1aeb 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/Android/MainApplication.cs @@ -1,4 +1,5 @@ -using Android.Runtime; +using Android.App; +using Android.Runtime; namespace MauiApp._1; diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs index 33e183c0833b..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/AppDelegate.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using Foundation; + +namespace MauiApp._1; [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate diff --git a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs index 8b50246ee003..c817b80805b2 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/MacCatalyst/Program.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using UIKit; + +namespace MauiApp._1; public class Program { diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs index 33e183c0833b..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/AppDelegate.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using Foundation; + +namespace MauiApp._1; [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate diff --git a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs index b6c946bf320c..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-blazor/Platforms/iOS/Program.cs @@ -1,4 +1,7 @@ -namespace MauiApp._1; +using UIKit; + +namespace MauiApp._1; + public class Program { // This is the main entry point of the application. diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs index 40856f5e1615..b189df660d25 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainActivity.cs @@ -1,4 +1,6 @@ -using Android.Content.PM; +using Android.App; +using Android.Content.PM; +using Android.OS; namespace MauiApp._1; diff --git a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs index cc57a5ca4692..83b97cfe1aeb 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/Android/MainApplication.cs @@ -1,4 +1,5 @@ -using Android.Runtime; +using Android.App; +using Android.Runtime; namespace MauiApp._1; diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs index 33e183c0833b..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/AppDelegate.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using Foundation; + +namespace MauiApp._1; [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate diff --git a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs index fab6c260ffef..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/MacCatalyst/Program.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using UIKit; + +namespace MauiApp._1; public class Program { diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs index 33e183c0833b..f703ee61a345 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/AppDelegate.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using Foundation; + +namespace MauiApp._1; [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate diff --git a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs index fab6c260ffef..9d4c5c10d63b 100644 --- a/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs +++ b/src/Templates/src/templates/maui-mobile/Platforms/iOS/Program.cs @@ -1,4 +1,6 @@ -namespace MauiApp._1; +using UIKit; + +namespace MauiApp._1; public class Program { From 8d042c5bdf8d2d391d760f2028fade03eda8cba6 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Fri, 29 Oct 2021 08:25:56 -0700 Subject: [PATCH 14/15] Revert back lib --- src/Templates/src/templates/maui-lib/MauiLib1.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Templates/src/templates/maui-lib/MauiLib1.csproj b/src/Templates/src/templates/maui-lib/MauiLib1.csproj index 3cb8afeb61c9..00b0b277a5b0 100644 --- a/src/Templates/src/templates/maui-lib/MauiLib1.csproj +++ b/src/Templates/src/templates/maui-lib/MauiLib1.csproj @@ -10,8 +10,8 @@ 14.2 14.0 21.0 - 10.0.18362.0 - 10.0.18362.0 + 10.0.17763.0 + 10.0.17763.0 From 6118f7f20842f33ab654e0ce59ac23f9b3f0d2d0 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 1 Nov 2021 19:59:49 +0200 Subject: [PATCH 15/15] No need for the alias --- src/Templates/src/templates/maui-blazor/App.xaml.cs | 6 ++---- src/Templates/src/templates/maui-mobile/App.xaml.cs | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Templates/src/templates/maui-blazor/App.xaml.cs b/src/Templates/src/templates/maui-blazor/App.xaml.cs index b16596eb00f4..68334f8da5d1 100644 --- a/src/Templates/src/templates/maui-blazor/App.xaml.cs +++ b/src/Templates/src/templates/maui-blazor/App.xaml.cs @@ -1,8 +1,6 @@ -using MauiApplication = Microsoft.Maui.Controls.Application; +namespace MauiApp._1; -namespace MauiApp._1; - -public partial class App : MauiApplication +public partial class App : Application { public App() { diff --git a/src/Templates/src/templates/maui-mobile/App.xaml.cs b/src/Templates/src/templates/maui-mobile/App.xaml.cs index b16596eb00f4..68334f8da5d1 100644 --- a/src/Templates/src/templates/maui-mobile/App.xaml.cs +++ b/src/Templates/src/templates/maui-mobile/App.xaml.cs @@ -1,8 +1,6 @@ -using MauiApplication = Microsoft.Maui.Controls.Application; +namespace MauiApp._1; -namespace MauiApp._1; - -public partial class App : MauiApplication +public partial class App : Application { public App() {