Me.Toolkit.Maui.Hosting
26.9.14
dotnet add package Me.Toolkit.Maui.Hosting --version 26.9.14
NuGet\Install-Package Me.Toolkit.Maui.Hosting -Version 26.9.14
<PackageReference Include="Me.Toolkit.Maui.Hosting" Version="26.9.14" />
<PackageVersion Include="Me.Toolkit.Maui.Hosting" Version="26.9.14" />
<PackageReference Include="Me.Toolkit.Maui.Hosting" />
paket add Me.Toolkit.Maui.Hosting --version 26.9.14
#r "nuget: Me.Toolkit.Maui.Hosting, 26.9.14"
#:package Me.Toolkit.Maui.Hosting@26.9.14
#addin nuget:?package=Me.Toolkit.Maui.Hosting&version=26.9.14
#tool nuget:?package=Me.Toolkit.Maui.Hosting&version=26.9.14
Me.Toolkit.Maui.Hosting
Sets the host environment name of a .NET MAUI app, so IsDevelopment() means something.
Ported from Xamarinme.Hosting — and it is deliberately much smaller than what it replaces.
Use
using Me.Toolkit.Maui.Hosting;
var builder = MauiApp.CreateBuilder();
builder.UseMeToolkitMauiHosting("Development");
Or take the name from configuration, which is how Xamarinme.Hosting worked:
builder.Configuration.AddAppPackageJson();
builder.UseMeToolkitMauiHostingFromConfiguration(); // reads "MAUI_ENVIRONMENT"
{ "MAUI_ENVIRONMENT": "Development" }
The key is read when IHostEnvironment is first resolved, not when the call is made, so the order
of the two lines does not matter. Pass a different key if MAUI_ENVIRONMENT does not suit;
Xamarinme called it XAMARIN_ENVIRONMENT.
Then inject the framework's own interface — there is no Me.Toolkit.Maui-specific one:
public sealed class Service(IHostEnvironment environment)
{
public bool IsDev => environment.IsDevelopment();
}
What comes from the platform
Only the environment name is Me.Toolkit.Maui's. ApplicationName, ContentRootPath and
ContentRootFileProvider are delegated to MAUI's own host environment, unchanged — including their
failure modes.
ContentRootPath throws NotImplementedException on Android, and this package passes that
through rather than inventing a value. Verified on a device. If you need a writable path, use
FileSystem.AppDataDirectory; if you need one for an ASP.NET Core content root,
AppContext.BaseDirectory is what Me.Toolkit.Maui.WebHostPatch defaults to.
Why this is so small
Xamarinme.Hosting existed because Xamarin had no hosting at all. It built a parallel
XamarinHostBuilder exposing Configuration, Services, Logging and an environment, plus an IHost
that threw NotImplementedException from both StartAsync and StopAsync.
MauiAppBuilder is that builder, and MAUI registers an IHostEnvironment of its own. The only gap
is that MAUI's always reports Production and its EnvironmentName setter throws. This package
wraps it, so the name can change while ApplicationName and ContentRootPath keep coming from the
platform.
If you only ever need a constant environment name, you do not need this package — but you do need to wrap rather than assign, which is the part that is easy to get wrong.
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.Maui.Core (>= 10.0.101)
-
net10.0-android36.0
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-ios26.0
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-maccatalyst26.0
- Microsoft.Maui.Core (>= 10.0.101)
-
net10.0-windows10.0.19041
- 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.Hosting 1.0.3, and is deliberately far smaller.
Xamarinme.Hosting existed because Xamarin had no hosting at all: it built a parallel XamarinHostBuilder exposing Configuration, Services, Logging and an environment, plus an IHost that threw NotImplementedException from both StartAsync and StopAsync. MauiAppBuilder is that builder, and MAUI registers an IHostEnvironment, so the environment name is all that was left to do.
UseMeToolkitMauiHosting sets the name. UseMeToolkitMauiHostingFromConfiguration reads it from a MAUI_ENVIRONMENT key, renamed from XAMARIN_ENVIRONMENT, when IHostEnvironment is first resolved - so it does not matter whether the configuration sources were added before or after.
The platform environment is wrapped rather than assigned to, because MauiHostEnvironment.EnvironmentName throws from its setter even though the interface declares it. ApplicationName and ContentRootPath still come from the platform.
There is no Me.Toolkit.Maui-specific environment interface. Inject the framework's IHostEnvironment.