-
Notifications
You must be signed in to change notification settings - Fork 708
Add Aspire.Hosting.Maui (.NET MAUI) Windows integration #12284
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
Changes from all commits
438cdf0
46a5ea4
ed758be
bf89ebb
2ab330d
a008c1d
919ee0b
962095d
8558d87
8f973ca
7d3cfcd
4bcb3e4
9e21c55
a017a0c
1c8c669
604e7df
d4d0d9b
3d41998
23d11bd
4566eef
29443e2
d2f0607
5fc6849
cc5f433
bf8d872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ function Get-Help() { | |
| Write-Host "Libraries settings:" | ||
| Write-Host " -testnobuild Skip building tests when invoking -test." | ||
| Write-Host " -buildExtension Build the VS Code extension." | ||
| Write-Host " -restore-maui Restore the MAUI workload after restore (only on Windows/macOS)." | ||
| Write-Host "" | ||
|
|
||
| Write-Host "Command-line arguments not listed above are passed through to MSBuild." | ||
|
|
@@ -109,3 +110,36 @@ if ($env:TreatWarningsAsErrors -eq 'false') { | |
|
|
||
| Write-Host "& `"$PSScriptRoot/common/build.ps1`" $arguments" | ||
| Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments" | ||
| $buildExitCode = $LASTEXITCODE | ||
|
|
||
| # Install MAUI workload after restore if -restore-maui was passed | ||
| # Only on Windows and macOS (MAUI doesn't support Linux) | ||
| $restoreMauiPassed = $properties -contains "-restore-maui" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jfversluis is the plan to also add a github workflow or something that is protecting this part of the script and ensuring it doesn't get broken? We should have some sort of protection by having a job that restores the workload and tries to build the maui playground project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! Opened this to track it for now: #12372 |
||
| $isWindowsOrMac = ($IsWindows -or $IsMacOS -or (-not (Get-Variable -Name IsWindows -ErrorAction SilentlyContinue))) | ||
| if ($restoreMauiPassed -and $buildExitCode -eq 0 -and $isWindowsOrMac) { | ||
| Write-Host "" | ||
| Write-Host "Installing MAUI workload into local .dotnet..." | ||
|
|
||
| $repoRoot = Split-Path $PSScriptRoot -Parent | ||
| $dotnetRoot = Join-Path $repoRoot ".dotnet" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not always be true, as there are cases where the machine-wide version matches the version in global.json then the build won't create a local .dotnet folder. Instead, this script should be calling the cc: @jfversluis |
||
| $dotnetExe = Join-Path $dotnetRoot "dotnet.exe" | ||
|
|
||
| if (Test-Path $dotnetExe) { | ||
| $env:DOTNET_ROOT = $dotnetRoot | ||
| $env:PATH = "$dotnetRoot;$env:PATH" | ||
|
|
||
| & $dotnetExe workload install maui 2>&1 | Out-Host | ||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "" | ||
| Write-Warning "Failed to install MAUI workload. You may need to run this command manually:" | ||
| Write-Warning " $dotnetExe workload install maui" | ||
| Write-Host "" | ||
| Write-Host "The MAUI playground may not work without the MAUI workload installed." | ||
| } | ||
| else { | ||
| Write-Host "MAUI workload installed successfully." | ||
| } | ||
| } | ||
| } | ||
|
|
||
| exit $buildExitCode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var weatherApi = builder.AddProject("webapi", @"../AspireWithMaui.WeatherApi/AspireWithMaui.WeatherApi.csproj"); | ||
|
|
||
| var mauiapp = builder.AddMauiProject("mauiapp", @"../AspireWithMaui.MauiClient/AspireWithMaui.MauiClient.csproj"); | ||
|
|
||
| mauiapp.AddWindowsDevice() | ||
| .WithReference(weatherApi); | ||
|
|
||
| builder.Build().Run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| <UserSecretsId>c086a0d6-b7a6-1337-a6a3-b62aa4616d88</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.Maui" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.DevTunnels" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17279;http://localhost:15173", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21046", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22093" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15173", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19172", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20091" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version = "1.0" encoding = "UTF-8" ?> | ||
| <Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:local="clr-namespace:AspireWithMaui.MauiClient" | ||
| x:Class="AspireWithMaui.MauiClient.App"> | ||
| <Application.Resources> | ||
| <ResourceDictionary> | ||
| <ResourceDictionary.MergedDictionaries> | ||
| <ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
| <ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
| </ResourceDictionary.MergedDictionaries> | ||
| </ResourceDictionary> | ||
| </Application.Resources> | ||
| </Application> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace AspireWithMaui.MauiClient; | ||
|
|
||
| public partial class App : Application | ||
| { | ||
| public App() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| protected override Window CreateWindow(IActivationState? activationState) | ||
| { | ||
| return new Window(new AppShell()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <Shell | ||
| x:Class="AspireWithMaui.MauiClient.AppShell" | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:local="clr-namespace:AspireWithMaui.MauiClient" | ||
| Title="AspireWithMaui.MauiClient"> | ||
|
|
||
| <TabBar> | ||
| <Tab Title="Weather" Icon="weather.png"> | ||
| <ShellContent | ||
| Title="Weather" | ||
| ContentTemplate="{DataTemplate local:MainPage}" | ||
| Route="weather" /> | ||
| </Tab> | ||
| <Tab Title="Environment" Icon="aspire_outline.png"> | ||
| <ShellContent | ||
| Title="Environment" | ||
| ContentTemplate="{DataTemplate local:EnvironmentPage}" | ||
| Route="environment" /> | ||
| </Tab> | ||
| </TabBar> | ||
|
|
||
| </Shell> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace AspireWithMaui.MauiClient; | ||
|
|
||
| public partial class AppShell : Shell | ||
| { | ||
| public AppShell() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks> | ||
| <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</TargetFrameworks> | ||
|
|
||
| <!-- Note for MacCatalyst: | ||
| The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64. | ||
| When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>. | ||
| The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated; | ||
| either BOTH runtimes must be indicated or ONLY macatalyst-x64. --> | ||
| <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> --> | ||
|
|
||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>AspireWithMaui.MauiClient</RootNamespace> | ||
| <UseMaui>true</UseMaui> | ||
| <SingleProject>true</SingleProject> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <!-- Disable CPM for this MAUI project --> | ||
| <ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally> | ||
|
|
||
| <!-- Disable strong name checking for playground sample --> | ||
| <NoWarn>$(NoWarn);CS8002</NoWarn> | ||
|
|
||
| <!-- Ignore unnecessary using directive warnings --> | ||
| <NoWarn>$(NoWarn);IDE0005</NoWarn> | ||
|
|
||
| <!-- Display name --> | ||
| <ApplicationTitle>AspireWithMaui.MauiClient</ApplicationTitle> | ||
|
|
||
| <!-- App Identifier --> | ||
| <ApplicationId>com.companyname.aspirewithmaui.mauiclient</ApplicationId> | ||
|
|
||
| <!-- Versions --> | ||
| <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
| <ApplicationVersion>1</ApplicationVersion> | ||
|
|
||
| <!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged --> | ||
| <WindowsPackageType>None</WindowsPackageType> | ||
|
|
||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion> | ||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion> | ||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> | ||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> | ||
| <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- App Icon --> | ||
| <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> | ||
|
|
||
| <!-- Splash Screen --> | ||
| <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> | ||
|
|
||
| <!-- Images --> | ||
| <MauiImage Include="Resources\Images\*" /> | ||
| <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="680,628" /> | ||
| <MauiImage Update="Resources\Images\aspire_outline.svg" Resize="True" BaseSize="256,256" /> | ||
| <MauiImage Update="Resources\Images\weather.png" Resize="True" BaseSize="512,512" /> | ||
|
|
||
| <!-- Custom Fonts --> | ||
| <MauiFont Include="Resources\Fonts\*" /> | ||
|
|
||
| <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> | ||
| <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Maui.Controls" Version="10.0.0-rc.1.25452.6" /> | ||
| <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0-rc.2.25465.106" /> | ||
| <PackageReference Include="System.Net.Http.Json" Version="10.0.0-rc.2.25465.106" /> | ||
| <PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0-rc.2.25465.106" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\AspireWithMaui.MauiServiceDefaults\AspireWithMaui.MauiServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure about this change. With SDK workloads, you want to be careful when you add dependencies to feeds that have unreleased versions of workloads or workload sets, as that can potentially put your machine in a torn state if a version is picked up and it depends on something else that is not part of the feed.
IMO we should probably consider reverting this particular feed, and instead see if there is a way to have the SDK team push only released versions into dotnet-public to prevent the above.
cc: @marcpopMSFT in case anything I said above is wrong.