Q:System.IO.FileNotFoundException Maui自定义的路径找不到
System.IO.FileNotFoundException: 'The configuration file 'Appsettings.json' was not found and is not optional. The expected physical path was '/data/user/0/com.companyname.MauiAppHostDemo/files/Appsettings.json'.'
A:静态文件(安卓下面通过File获取不到文件)
https://learn.microsoft.com/zh-cn/dotnet/maui/user-interface/images/images?view=net-maui-7.0
//#region 注入配置文件
using var streamAppsettings = FileSystem.OpenAppPackageFileAsync("Appsettings.json").Result;
using var streamAppRouterApi = FileSystem.OpenAppPackageFileAsync("AppRouterApi.json").Result;
var Configuration = AppProviderUtil.BuilderApiSettins(streamAppsettings, streamAppRouterApi).Build();
builder.Services.AddSingleton<IConfiguration>(Configuration);
//#endregion 注入配置文件
A:改成使用官网的 OpenAppPackageFileAsync
文档更新时间: 2023-04-20 11:34 作者:admin