Home > Software design >  What is the difference between <UseMauiEssentials> and <UseMaui> in the Android/iOS cspr
What is the difference between <UseMauiEssentials> and <UseMaui> in the Android/iOS cspr

Time:12-28

I want to use .NET MAUI in my existing Android and iOS projects but I'm not sure if I need to add UseMauiEssentials and UseMaui or only one of them to my existing csproj files. Currently I use Xamarin.Essentials and some other Xamarin NuGet packages in my Android and iOS projects.

My Android csproj:

`

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-android</TargetFramework>
    <SupportedOSPlatformVersion>23</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <ApplicationId>com.companyname.AndroidprojectwithXamarin</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
    <PackageReference Include="MonoGame.Framework.Android" Version="3.8.1.303" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
  </ItemGroup>
  <Target Name="RestoreDotnetTools" BeforeTargets="Restore">
    <Message Text="Restoring dotnet tools" Importance="High" />
    <Exec Command="dotnet tool restore" />
  </Target>
</Project>

`

My iOS csproj: `

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-ios</TargetFramework>
    <OutputType>Exe</OutputType>
    <SupportedOSPlatformVersion>15.0</SupportedOSPlatformVersion>
    <CodesignKey>iPhone Developer</CodesignKey>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <CreatePackage>false</CreatePackage>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <CreatePackage>false</CreatePackage>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
    <PackageReference Include="MonoGame.Framework.iOS" Version="3.8.1.303" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
  </ItemGroup>
  <Target Name="RestoreDotnetTools" BeforeTargets="Restore">
    <Message Text="Restoring dotnet tools" Importance="High" />
    <Exec Command="dotnet tool restore" />
  </Target>
</Project>

`

What is the difference between UseMauiEssentials and UseMaui in the Android/iOS csproj files? Should I use both in my csproj files? Is it necessary to remove the Xamarin.Essentials NuGet package from my projects? Is it necessary to add another .NET MAUI NuGet package if I want to use .NET MAUI? Or should I leave the Xamarin.Essentials NuGet package installed?

CodePudding user response:

As you've already found, Xamarin.Essentials was a separate project. Essentials was basically an abstraction layer for all kinds of APIs that are available across the different platforms (iOS, Android, Windows) but don't necessarily have any UI.

Since Xamarin.Forms was a UI framework, all of Essentials was not included in Forms. In fact, you can use Xamarin.Essentials with a traditional Xamarin application if you want, there is no dependency on Forms.

With the introduction of .NET MAUI, Essentials as a separate concept kind of went away. Essentials is now an integrated part of .NET MAUI and it's just APIs that are available for you to use.

However, those APIs still have no dependency on .NET MAUI and you should be able to use Essentials without using .NET MAUI. And that is where we get to the answer of this question: use UseMauiEssentials if you just want to use the APIs formerly known as Essentials, or, if you're going to use all of .NET MAUI anyway, just include UseMaui that will also bring in Essentials automatically.

  • Related