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

Implement .NET 6 features for templates. #3018

Merged
merged 24 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1fbec27
Implement .NET 6 features for templates. Implicit/Global Usings, Scop…
jamesmontemagno Oct 18, 2021
74c8735
Updates based on feedback
jamesmontemagno Oct 18, 2021
375df93
Forecast
jamesmontemagno Oct 18, 2021
1a469de
Sort usings
jamesmontemagno Oct 18, 2021
2392b30
revert back blazor weather stuff
jamesmontemagno Oct 19, 2021
cf1ed40
More changes based on feedback
jamesmontemagno Oct 19, 2021
7718ff3
Adjjust appxmanifest for tempaltes
jamesmontemagno Oct 20, 2021
3202407
Merge branch 'main' into dotnet6ify-templates
jamesmontemagno Oct 20, 2021
fefc64b
comment out windows again
jamesmontemagno Oct 25, 2021
12eb743
Cleanup merges
jamesmontemagno Oct 25, 2021
84be08b
Merge branch 'dotnet:main' into dotnet6ify-templates
jamesmontemagno Oct 25, 2021
dac8e2a
Update MauiApp.1.csproj
jamesmontemagno Oct 25, 2021
84a7e41
Update MauiApp.1.csproj
jamesmontemagno Oct 25, 2021
043e0c9
revert changes back
jamesmontemagno Oct 26, 2021
fbdf533
Merge branch 'dotnet6ify-templates' of https://github.com/jamesmontem…
jamesmontemagno Oct 26, 2021
2675ba8
Changes based on conversation
jamesmontemagno Oct 26, 2021
85828ea
Add back usings from native platforms
jamesmontemagno Oct 26, 2021
0987eb2
Merge branch 'dotnet:main' into dotnet6ify-templates
jamesmontemagno Oct 26, 2021
4845597
Merge branch 'release/6.0.1xx-preview10' into dotnet6ify-templates
jamesmontemagno Oct 28, 2021
8d042c5
Revert back lib
jamesmontemagno Oct 29, 2021
4d4c0a6
Merge branch 'dotnet6ify-templates' of https://github.com/jamesmontem…
jamesmontemagno Oct 29, 2021
a8a4c10
Merge remote-tracking branch 'origin/main' into pr/3018
mattleibow Nov 1, 2021
6118f7f
No need for the alias
mattleibow Nov 1, 2021
0d0e9dc
Merge remote-tracking branch 'origin/main' into pr/3018
mattleibow Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/Templates/src/templates/maui-blazor/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using Application = Microsoft.Maui.Controls.Application;
using MauiApplication = Microsoft.Maui.Controls.Application;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use MauiApplication?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @jamesmontemagno this one change was reverted because it wasn't clear it's necessary and it might create even more confusion with MAUI's 4 or 5 different "Application" types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fine to me... why was it ever needed? Is application a conflict with the new usings at all though?


namespace MauiApp._1
namespace MauiApp._1;

public partial class App : MauiApplication
{
public partial class App : Application
public App()
{
public App()
{
InitializeComponent();
InitializeComponent();

MainPage = new MainPage();
}
MainPage = new MainPage();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
namespace MauiApp._1.Data;

namespace MauiApp._1.Data
public class WeatherForecast
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public DateTime Date { get; set; }

public int TemperatureC { get; set; }
public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
public string Summary { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
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<WeatherForecast[]> GetForecastAsync(DateTime startDate)
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
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());
}
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}

14 changes: 14 additions & 0 deletions src/Templates/src/templates/maui-blazor/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Maui;
global using Microsoft.Maui.Controls;
global using Microsoft.Maui.Controls.Hosting;
jamesmontemagno marked this conversation as resolved.
Show resolved Hide resolved
global using Microsoft.Maui.Controls.Xaml;
global using Microsoft.Maui.Essentials;
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;
12 changes: 4 additions & 8 deletions src/Templates/src/templates/maui-blazor/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
38 changes: 16 additions & 22 deletions src/Templates/src/templates/maui-blazor/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -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<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
var builder = MauiApp.CreateBuilder();
builder
.RegisterBlazorMauiWebView()
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});

builder.Services.AddBlazorWebView();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddBlazorWebView();
builder.Services.AddSingleton<WeatherForecastService>();

return builder.Build();
}
return builder.Build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using Android.App;
using Android.Content.PM;
using Microsoft.Maui;
using Android.OS;

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)
jamesmontemagno marked this conversation as resolved.
Show resolved Hide resolved
{
Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using System;
using Android.App;
using Android.App;
using Android.Runtime;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;

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();
}
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
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();
}
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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));
}
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : MauiWinUIApplication
{
/// <summary>
/// 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().
/// </summary>
public partial class App : MauiWinUIApplication
public App()
{
/// <summary>
/// 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().
/// </summary>
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);
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
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();
}
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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));
}
}
}
11 changes: 4 additions & 7 deletions src/Templates/src/templates/maui-lib/Class1.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
}
}
Loading