Me.Toolkit.Maui.Configuration
26.9.14
dotnet add package Me.Toolkit.Maui.Configuration --version 26.9.14
NuGet\Install-Package Me.Toolkit.Maui.Configuration -Version 26.9.14
<PackageReference Include="Me.Toolkit.Maui.Configuration" Version="26.9.14" />
<PackageVersion Include="Me.Toolkit.Maui.Configuration" Version="26.9.14" />
<PackageReference Include="Me.Toolkit.Maui.Configuration" />
paket add Me.Toolkit.Maui.Configuration --version 26.9.14
#r "nuget: Me.Toolkit.Maui.Configuration, 26.9.14"
#:package Me.Toolkit.Maui.Configuration@26.9.14
#addin nuget:?package=Me.Toolkit.Maui.Configuration&version=26.9.14
#tool nuget:?package=Me.Toolkit.Maui.Configuration&version=26.9.14
Me.Toolkit.Maui.Configuration
appsettings.json for .NET MAUI apps, from the app package or from embedded resources, with the
usual appsettings.{environment}.json overlay.
Ported from Xamarinme.Configuration.
Use
Mark the file as a MauiAsset:
<ItemGroup>
<MauiAsset Include="appsettings.json" />
<MauiAsset Include="appsettings.Development.json" />
</ItemGroup>
Then, in MauiProgram:
using Me.Toolkit.Maui.Configuration;
var builder = MauiApp.CreateBuilder();
builder.Configuration.AddAppPackageJson(environment: "Development");
Or keep the file as an EmbeddedResource, which is what Xamarinme did:
builder.Configuration.AddEmbeddedResourceJson(
typeof(App).Assembly, prefix: "MyApp", environment: "Development");
prefix is the default namespace plus any folders the file sits in, dot-separated — MyApp.res for
a file in a res folder.
Both take optional: false if a missing file should throw rather than be skipped, and the exception
names the file and where it looked.
What this adds over plain MAUI
MAUI references Microsoft.Extensions.Configuration but not the JSON provider, so
builder.Configuration has no AddJsonStream. That is what this package supplies, along with the
environment overlay and the two ways of finding the file. The parsing is Microsoft's.
Xamarinme vendored a copy of Microsoft's Newtonsoft-era JsonConfigurationFileParser — the one
Microsoft replaced with a System.Text.Json implementation in .NET Core 3.0 — and froze it there,
with a Newtonsoft.Json dependency attached. Nothing is vendored here.
One behavioural difference from Xamarinme.Configuration is worth knowing: a JSON null used to
read as "", so the key existed; it is now absent, and GetValue<T> falls back to the default.
Booleans still render "True" — both parsers do that, so a string comparison against "true" was
always wrong. Use GetValue<bool>.
Documentation
Full documentation is in the wiki — Design Notes for why each library is shaped the way it is, Building and Testing for the multi-targeting rules, and Publishing for how these packages are released.
Source: github.com/melihercan/Me.Toolkit.Maui
Licence
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-maccatalyst26.0 is compatible. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net10.0-windows10.0.19041 is compatible. |
-
net10.0
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-android36.0
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-ios26.0
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-maccatalyst26.0
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-windows10.0.19041
- Microsoft.Extensions.Configuration.Json (>= 10.0.12)
- Microsoft.Maui.Core (>= 10.0.101)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
26.9.9 renames the assemblies and namespaces to match the package ID. 26.9.8 shipped the correct package ID around assemblies still called Mauime.*, so consuming it meant writing using Mauime.X against a package called Me.Toolkit.Maui.X; it is unlisted. Nothing else changed.
First release. Replaces Xamarinme.Configuration 1.0.2, which was for Xamarin.
AddAppPackageJson reads a MauiAsset; AddEmbeddedResourceJson reads an embedded resource, which is the path Xamarinme offered and still works. Both layer appsettings.{environment}.json over the base file, and both name the file and where they looked when a required one is missing.
Parsing is Microsoft.Extensions.Configuration.Json's. Xamarinme vendored a copy of Microsoft's Newtonsoft-era parser and froze it there, with a Newtonsoft.Json dependency attached. Nothing is vendored here.
One behavioural difference from Xamarinme.Configuration: a JSON null used to read as an empty string, so the key existed; it is now absent, and binding falls back to the default. Booleans still render "True" - both parsers do that, so a string comparison against "true" was always wrong.
The options object is gone, and with it the three ways it could be left half-filled and produce a NullReferenceException out of Build, or, for a wrong prefix, an empty configuration and no error at all.