MacOS下.NET MAUI Release模式构建及运行崩溃问题求助
一、Release模式构建错误
在MacOS的Visual Studio 2022中开发.NET MAUI(Mac Catalyst)应用,Debug模式下构建运行完全正常,但切换到Release模式构建时出现以下错误:
Assets file '/Users/bliink/Documents/BLiiNK/BLiiNK/obj/project.assets.json' doesn't have a target for 'net7.0-maccatalyst/maccatalyst-arm64'. Ensure that restore has run and that you have included 'net7.0-maccatalyst' in the TargetFrameworks for your project. You may also need to include 'maccatalyst-arm64' in your project's RuntimeIdentifiers. (NETSDK1047)
项目引用的NuGet包如下:
<ItemGroup> <PackageReference Include="CommunityToolkit.Maui" Version="5.2.0" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" /> <PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-beta.710" /> <PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.0" /> <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="PInvoke.User32" Version="0.7.124" /> <PackageReference Include="Portable.BouncyCastle" Version="1.9.0" /> <PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" /> <PackageReference Include="System.Management" Version="8.0.0-preview.4.23259.5" /> <PackageReference Include="System.Resources.Extensions" Version="7.0.0" /> </ItemGroup>
二、构建成功后运行崩溃
按照Alexandar May - MSFT的建议解决构建问题后,运行maccatalyst-arm64文件夹中的应用包时出现崩溃,错误日志如下:
翻译后的报告(完整报告见下方)
进程: TestApp [3684]
路径: /Users/USER/Documents/*/TestApp.app/Contents/MacOS/TestApp
标识符: com.testapp.TestApp
版本: 2.1.4 (1)
代码类型: ARM-64 (原生)
父进程: launchd [1]
用户ID: 501日期/时间: 2023-12-09 17:00:11.4111 +0400
系统版本: macOS 14.1.2 (23B92)
报告版本: 12
匿名UUID: 64A2D3A6-74FA-1C35-D3DF-AFB84C4D008E睡眠/唤醒UUID: 4DB3887F-9027-4B32-A18D-16E0CC7CD222
系统启动后唤醒时间: 14000秒
上次唤醒后时间: 6387秒系统完整性保护: 已启用
崩溃线程: 0 tid_103 调度队列: com.apple.main-thread
异常类型: EXC_CRASH (SIGABRT)
异常代码: 0x0000000000000000, 0x0000000000000000终止原因: 命名空间 SIGNAL, 代码 6 中止陷阱: 6
终止进程: TestApp [3684]完整报告
{"app_name":"TestApp","timestamp":"2023-12-09 17:00:25.00 +0400","app_version":"2.1.4","slice_uuid":"f7125eac-c00d-32c7-a7d3-6c3fd0b788af","build_version":"1","platform":6,"bundleID":"com.testapp.TestApp","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 14.1.2 (23B92)","roots_installed":0,"name":"TestApp","incident_id":"A0A2B50E-7826-4298-92CA-1BDBF53D8C6F"} { "uptime" : 14000, "procRole" : "Foreground", "version" : 2, "userID" : 501, "deployVersion" : 210, "modelCode" : "MacBookPro18,1", "coalitionID" : 3328, "osVersion" : { "train" : "macOS 14.1.2", "build" : "23B92", "releaseType" : "User" }, "captureTime" : "2023-12-09 17:00:11.4111 +0400", "codeSigningMonitor" : 1, "incident" : "A0A2B50E-7826-4298-92CA-1BDBF53D8C6F", "pid" : 3684, "translated" : false, "cpuType" : "ARM-64", "roots_installed" : 0, "bug_type" : "309", "procLaunch" : "2023-12-09 17:00:03.1434 +0400", "procStartAbsTime" : 338575444283, "procExitAbsTime" : 338773533538, "procName" : "TestApp", "procPath" : "/Users/USER/Documents/*/TestApp.app/Contents/MacOS/TestApp", "bundleInfo" : {"CFBundleShortVersionString":"2.1.4","CFBundleVersion":"1","CFBundleIdentifier":"com.testapp.TestApp"}, "storeInfo" : {"deviceIdentifierForVendor":"BE4C2045-5ABA-5E0F-981C-16F2CE6C5EF2","thirdParty":true}, "parentProc" : "launchd", "parentPid" : 1, "coalitionName" : "com.testapp.TestApp", "crashReporterKey" : "64A2D3A6-74FA-1C35-D3DF-AFB84C4D008E", "codeSigningID" : "com.testapp.TestApp", "codeSigningTeamID" : "", "codeSigningFlags" : 570425857, "codeSigningValidationCategory" : 10, "codeSigningTrustLevel" : 4294967295, "instructionByteStream" : {"beforePC":"fyMD1f17v6n9AwCRXOD/l78DAJH9e8Go/w9f1sADX9YQKYDSARAA1A==","atPC":"AwEAVH8jA9X9e7+p/QMAkVHg/5e/AwCR/XvBqP8PX9bAA1/WcAqA0g=="}, "wakeTime" : 6387, "sleepWakeUUID" : "4DB3887F-9027-4B32-A18D-16E0CC7CD222", "sip" : "enabled", "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"}, "termination" : {"flags":0,"code":6,"namespace":"SIGNAL","indicator":"Abort trap: 6","byProc":"TestApp","byPid":3684}, "asi" : {"libsystem_c.dylib":["abort() called"]}, "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0}, "faultingThread" : 0, "sharedCache" : { "base" : 6538444800, "size" : 4018896896, "uuid" : "6d1aeeac-d56f-3513-9ae1-3894fde828f3" }, "legacyInfo" : { "threadTriggered" : { "name" : "tid_103", "queue" : "com.apple.main-thread" } }, "logWritingSignature" : "b3a666d970e84e599ac2fea6bb49e737b4caa5de", "trialInfo" : { "rollouts" : [ { "rolloutId" : "6112d17137f5d11121dcd4e2", "factorPackIds" : { }, "deploymentId" : 240000464 }, { "rolloutId" : "60186475825c62000ccf5450", "factorPackIds" : { }, "deploymentId" : 240000068 } ] } }型号: MacBookPro18,1, BootROM 10151.41.12, 处理器 10:8:2, 16 GB, SMC
显卡: Apple M1 Pro, Apple M1 Pro, 内置
显示器: 彩色LCD, 3456 x 2234 Retina, 主显示器, 未镜像, 在线
内存模块: LPDDR5, Hynix
内容的提问来源于stack exchange,提问作者Archie

