我正在使用Entity Framework Core 3.1和SQLite数据库将Xamarin Forms 5.0应用程序迁移到. NET MAUI 6.0和Entity Framework Core 6.0。调试版本工作正常,但当我进行发布版本时,应用程序在启动时崩溃。
要在macOS上重现它,最简单的方法是在Visual Studio中使用. NET MAUI App模板,编辑项目文件并添加一些配置,以确保您可以使用dotnet build
(Release builds from Visual Studio for Mac don't work at the moment):
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
<CodesignProvision>Automatic</CodesignProvision>
<CodesignKey>iPhone Developer</CodesignKey>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
<CodesignProvision>Automatic</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>
在终端中打开项目文件夹,然后运行
dotnet build MauiEFCore.csproj -c Release -f net6.0-ios -t:Run -p:_DeviceName=<Device UDID>
(be确保指定了正确的项目文件,以及你iPhone的UDID)。这是可行的,但是一旦你将实体框架核心添加到项目中:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.11" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.3" />
</ItemGroup>
应用程序在启动时开始崩溃。关于Microsoft.Maui.Graphics的错误似乎无关-这只是一个标准的Maui模块,对吗?我在控制台应用程序中也找不到更多信息。
Launched application 'com.companyname.mauiefcore' on 'Gerwin's iPhone 11' with pid 25752
2023-01-06 16:00:53.767 MauiEFCore[25752:10999573] error: Failed to load AOT module 'Microsoft.Maui.Graphics' while running in aot-only mode because a dependency cannot be found or it is out of date.
=================================================================
Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x104228540 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x104211788 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x104227d28 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x1f2ed0a90 - /usr/lib/system/libsystem_platform.dylib : <redacted>
0x1f2f6c1ac - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
0x1ac554c8c - /usr/lib/system/libsystem_c.dylib : abort
0x103f6d5d4 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_find_protocol_wrapper_type
0x104264d10 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x104264e44 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x104200664 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x1040c9ea8 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x1040c9900 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x1040cb5bc - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x103f6cbf8 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_get_block_descriptor
0x10426cb64 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x103f7685c - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : xamarin_log
0x10426cd04 - /private/var/containers/Bundle/Application/F14C623C-8C03-4845-94D8-C0B1EFBA07A6/PublicStaging.app/MauiEFCore : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
0x1c3776960 - /usr/lib/dyld : <redacted>
=================================================================
Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1e284f160):0x1e284f150 ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4 .._..._..)......
0x1e284f160 03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ...T.#...{......
0x1e284f170 8e ed ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6 .........{...._.
0x1e284f180 c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 .._..#...{......
=================================================================
Managed Stacktrace:
=================================================================
=================================================================
Application 'com.companyname.mauiefcore' terminated (with exit code '' and/or crashing signal '6).
Build succeeded.
因为Debug构建继续工作,所以我怀疑链接是罪魁祸首;然而,disabling linking(相当于将<MtouchLink>None</MtouchLink>
添加到项目文件中)没有任何效果。我仍然在构建输出中看到以下行:
优化程序集的大小可能会更改应用的行为。请确保在发布后进行测试。请参阅:https://aka.ms/dotnet-illink
优化程序集的大小。此过程可能需要一段时间。
这个链接指向一个关于 * trimming * 的页面,这是意料之外的,因为我没有启用trimming,但显然它是自动的,关闭它会导致另一个错误:
/usr/本地/共享/dotnet/包/微软. iOS. sdk/16.1.229/目标/Xamarin.共享. sdk.目标(269,3):错误:生成iOS项目时必须使用PublishTrimmed = true。当前值:错。
在我的Xamarin Forms项目中,我在"iOS Build options"中的"Additional mtouch arguments"中添加了--linkskip System.Core
,如下所述,但这没有帮助-详细的构建输出显示它被忽略了:
Task "ParseBundlerArguments"
Skipping unknown argument 'linkskip' with value ''
Done executing task "ParseBundlerArguments".
我需要做什么才能让实体框架核心在发布模式下工作?
我尝试过添加链接器设置,如this answer中所述,甚至添加了一些其他程序集到该列表(Microsoft.EntityFrameworkCore.Abstractions
和SQLitePCLRaw.provider.internal
),但无济于事。
FWIW,对于Android,发布版本运行良好。
1条答案
按热度按时间wljmcqd81#
正如GitHub user @Ghevi在这里提到的,通过在项目文件中设置MSBuild属性
UseInterpreter
来使用解释器可以完成这项工作: