.NET MAUI
開発環境
VS2022Previewを使う
VS2022でやるならなるべく最新に(少なくとも17.0.1では使えなかった。17.1.6ならOK)
dotnet workload install maui
↑もっと少なくても出来ると思うが、最小単位は調べてない。
動かない時は、ポイントとしてbinとobjはなるべく都度消した方が良い。クリーンでは消えない。
これでビルドは通ったが、実行するとエラー
https://scrapbox.io/files/626d1f478ee54c002319aa96.png
DEP0700: Registration of the app failed. 0x80073CF9 error 0x80070020: Windows cannot access deployment target at AppX.iso2022jp.icon ----
既定でビルドできない問題
最初から試してみた
dotnet new で作成
code:wt
dotnet new MauiApp3
The template ".NET MAUI App (Preview)" was created successfully.
cd MauiApp3
code:MauiApp3.csproj
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuild::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks> 既定の構成だと全プラットフォームがビルド対象 (TargetFrameworks) に入っている
ここ数年で選べるようになったマルチターゲット方式のファイル
Mac では Windows がビルドターゲットから外れている
CLI でビルド
ios の Workload を求めてくる
code:dotnet
dotnet build
dotnet build では後者の condition つきの行を認識していない?iso2022jp.icon
dotnet msbuild コマンドなら認識できるのか気になりましたebi_chan.icon
dotnet msbuild MyMauiApp.csproj -t:Rebuild -p:TargetFramework=net6.0-maccatalyst
dotnet msbuild MyMauiApp.csproj -t:Run -p:TargetFramework=net6.0-maccatalyst
↑Macではこれでビルド&実行できたので、TargetFrameworkをwindows(or windows10.0.xxxxx?)にしてどうなるか
code:Windows Terminal
dotnet msbuild MauiApp3.csproj -t:Rebuild -p:TargetFramework=net6.0-windows10.0.19041
C:\Program Files\dotnet\sdk\7.0.100-preview.1.22110.4\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolut
ion.targets(267,5): error NETSDK1047: Assets file 'U:\home\kes\Dropbox\projects\works\next-gui\MauiApp3\obj\project.ass
ets.json' doesn't have a target for 'net6.0-windows10.0.19041/win10-x64'. Ensure that restore has run and that you have
included 'net6.0-windows10.0.19041' in the TargetFrameworks for your project. You may also need to include 'win10-x64'
code:Windows Terminal
dotnet msbuild MauiApp3.csproj -t:Rebuild -p:TargetFramework=net6.0-windows
C:\Program Files\dotnet\sdk\7.0.100-preview.1.22110.4\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInfer
.NET SDK 7 というのがちょっとアレ iso2022jp.icon
仮に認識してたとしても、$(TargetFrameworks) が含まれているので net6.0-android;net6.0-ios;net6.0-maccatalyst がビルド対象になってしまう?
既定では CLI でビルドできない可能性がある
Visual Studio でビルド
code:Output
1>------ Rebuild All started: Project: MauiApp3, Configuration: Debug Any CPU ------
Failed to restore U:\home\kes\Dropbox\projects\works\next-gui\MauiApp3\MauiApp3.csproj (in 5 ms).
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
1>C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: macos
1>C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload install macos
1>Done building project "MauiApp3.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
MAUI Blazor
dotnet new maui-blazor -n MauiBlazor
dotnet build
error NETSDK1147: To build this project, the following workloads must be installed: android
dotnet workload install android
dotnet workload list
code:Output
Installed Workload Ids
----------------------
android
maui-maccatalyst
maui-windows
dotnet build
error NETSDK1147: To install these workloads, run the following command: dotnet workload install ios
dotnet workload install ios
dotnet workload list
code:Output
Installed Workload Ids
----------------------
android
ios
maui-maccatalyst
maui-windows
dotnet build
Build succeeded.iso2022jp.icon