# Build with .NET

Choose native .NET, MAUI, or Uno setup, then add events, errors, consent, and optional geofence planning to your app.

Source: https://appportal.io/docs/sdks/dotnet

Start with the UI framework in your executable app. Each guide takes you from installing the
right package to starting one AppPortal client. Your shared C# code uses the same telemetry API.

## Install from NuGet

The public 3.0.384 release is available on NuGet.org for [plain .NET](https://appportal.io/docs/sdks/dotnet/telemetry#start-a-plain-managed-host),
[MAUI](https://appportal.io/docs/sdks/dotnet/maui), and [Uno](https://appportal.io/docs/sdks/dotnet/uno). Use the matching adapter
and runtime versions. If AppPortal supplied a different release, use the package source and
version from that release.

## What are you building?

- **[.NET MAUI](https://appportal.io/docs/sdks/dotnet/maui)** — initialize in native startup before MAUI, register the existing client in DI, track visible pages automatically, and opt into Shell navigation timing.
- **[Uno Platform](https://appportal.io/docs/sdks/dotnet/uno)** - initialize supported Skia heads on Android, Apple and Desktop, then observe Frame navigation; check the guide's native WinUI and BrowserWasm limitations.
- **[Native Android or iOS UI in C#](https://appportal.io/docs/sdks/dotnet/native-mobile)** - initialize before the Android Application base constructor or iOS application startup.

For a WPF, Windows Forms, or other managed .NET app, use `AppPortal.Telemetry` at the application
composition root. The [shared .NET guide](https://appportal.io/docs/sdks/dotnet/telemetry#start-a-plain-managed-host) covers that setup.
Check [target coverage](https://appportal.io/docs/sdks/compatibility) for your host. The typed Avalonia integration is described
[below](#avalonia); generic managed setup alone does not attach its lifecycle or navigation hooks.

Prism is optional. Native, MAUI, Uno, desktop, and headless code can use the SDK directly or inject
`IAppPortalClient`. In a Prism application, initialize the SDK first, then add the logging or Region
adapter for the APIs that application already uses. A background entry point that has no Prism
container can call the already-initialized SDK directly.

## Avalonia

The current SDK source provides `AppPortal.Telemetry.Avalonia` over the same Telemetry runtime.
Choose it only with an exact compatible package supplied by your release channel; this source
example does not establish package publication or execution on every Avalonia target. The integration
supports the Avalonia 11.3 API floor; the integration app is a separate compatibility check.

```bash
dotnet add package AppPortal.Telemetry.Avalonia --version "3.0.401"
```

In the existing desktop `Program` class, replace its `BuildAvaloniaApp` method so telemetry starts
before constructing the Avalonia `Application`, then attach framework observation to that same runtime:

```csharp
using AppPortal;
using Avalonia;

public static AppBuilder BuildAvaloniaApp()
{
    var createApp = AppPortalSdk.CreateBuilder("<app-credential>")
        .Start(() => new App());
    return AppBuilder.Configure(createApp).UsePlatformDetect().UseAppPortal();
}
```

Keep the existing desktop lifetime call and app class. Consent remains pending until your application's
normal consent action, or an explicitly permitted initial choice; follow [consent setup](https://appportal.io/docs/sdks/dotnet/telemetry#connect-your-consent-ui).
Android initializes from its native Application constructor using the existing handle; iOS initializes
before `UIApplication.Main`. Do not move mobile initialization into this desktop factory or create
another runtime during `UseAppPortal()`.

For plain content navigation, call `primaryContent.ObserveAppPortalNavigation()` once at the primary
`ContentControl` composition root. It records visible control type names, not view-model values or
route input. Prism Region applications use the existing Prism navigation adapter instead of a second
observer on that primary surface. Keep the observer for the content host's lifetime.

Native lifecycle ownership takes precedence over framework fallback, preventing duplicate transitions.
Recovered dispatcher errors do not change the application's exception handling; fatal capture remains
runtime-specific. A managed or headless test does not qualify all desktop/mobile/browser targets, and
browser in-memory queues do not promise restart recovery. Keep actual package/host evidence with
[the first-value check](https://appportal.io/docs/getting-started/verify-first-value).

## After setup

**[Add useful telemetry](https://appportal.io/docs/sdks/dotnet/telemetry)** covers getting the client, consent, logs, events, managed
exceptions, automatic lifecycle tracking, and session investigation. Start there once your framework guide is complete; you do
not need to configure the runtime again in each view model or shared library.

Add these integrations when your app uses them:

- [Prism logging and optional navigation](https://appportal.io/docs/sdks/dotnet/prism), using the client initialized by native startup.
- [Messaging](https://appportal.io/docs/sdks/messaging), for push and Message Center workflows.
- [Geofence planning](https://appportal.io/docs/sdks/dotnet/geofencing), for app-owned metadata filters and activation windows.

Messaging and Location are source previews. The 3.0.384 NuGet release contains telemetry
packages. Check [feature availability](https://appportal.io/docs/getting-started/feature-availability)
before evaluating a preview.

Use one app credential for the environment you are connecting.

Finish with [one known event and crash/restart check](https://appportal.io/docs/getting-started/verify-first-value).
Keep the resolved package version and actual native host/renderer with the result: a successful
managed compile does not qualify every MAUI, Uno or native target. The current guide uses the
single Uno integration and one runtime initialized at the native root; framework registration
exposes that same client. Follow [version notes](https://appportal.io/docs/getting-started/documentation-versions)
when an installed release differs rather than replacing working package IDs from an architecture plan.
