Back to results for “Native Interop & Libraries”
.NET MAUI › Native Interop & Libraries

How do you share code between a MAUI app and other .NET projects (web/API)?

Intermediate

Answer

Put shared models, DTOs, validation, and business logic in a plain .NET class library referenced by both the MAUI app and the server. Keep platform and UI concerns out of it. This maximizes reuse and keeps a single source of truth for contracts.
// Shared.csproj referenced by MyApp.Maui and MyApp.Api
public record ProductDto(int Id, string Name, decimal Price);
Real-world example The same DTOs and validation rules compile into both the API and the MAUI client, preventing contract drift.

Common follow-ups: What belongs in the shared library? | Why keep UI out of it?