I'm upgrading a Xamarin Forms project to MAUI taking the projects to .NET 8 and everything seems to be working alright until I try and run tests. The app works and all of my tests show in the Test Explorer.
I get the following error:
========== Test run aborted: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========
Building Test Projects
Starting test discovery for requested test run
========== Starting test discovery ==========
You must install or update .NET to run this application.
App: C:\Path\To\App\bin\Debug\net8.0-android34.0\testhost.exe
Architecture: x64
Framework: 'Microsoft.Android', (x64)
.NET location: C:\Program Files\dotnet
No frameworks were found.
My dotnet root is: C:\Program Files\dotnet
.
runtimes:
C:\Program Files\dotnet\sdk> dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
sdks
C:\Program Files\dotnet\sdk> dotnet --list-sdks
8.0.407 [C:\Program Files\dotnet\sdk]
9.0.201 [C:\Program Files\dotnet\sdk]
9.0.202 [C:\Program Files\dotnet\sdk]
workloads (I find it a little odd that maui-android has no VS version listed)
C:\Program Files\dotnet\sdk> dotnet workload list
Installed Workload Id Manifest Version Installation Source
--------------------------------------------------------------------------------
android 35.0.50/9.0.100 SDK 9.0.200, VS 17.13.35919.96
ios 18.2.9180/9.0.100 SDK 9.0.200, VS 17.13.35919.96
maccatalyst 18.2.9180/9.0.100 SDK 9.0.200, VS 17.13.35919.96
maui-android 9.0.14/9.0.100 SDK 9.0.200
maui-windows 9.0.14/9.0.100 SDK 9.0.200, VS 17.13.35919.96
My target framework is set:
<TargetFramework>net8.0-android34.0</TargetFramework>
Here are my dependencies:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="Moq" Version="4.13.1"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.8.3"/>
<PackageReference Include="MSTest.TestFramework" Version="3.8.3"/>
<PackageReference Include="sqlite-net-pcl" Version="1.9.172"/>
<PackageReference Include="SQLiteNetExtensions" Version="2.1.0"/>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0"/>
</ItemGroup>
Here is the csproj file for my Unit Test Project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android</TargetFramework>
<OutputType>Library</OutputType>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Configurations>Debug;iOS Debug;iOS Release;Release</Configurations>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AssemblyTitle>Mobile.Tests</AssemblyTitle>
<Product>Mobile.Tests</Product>
<Copyright>Copyright © 2018</Copyright>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CodeAnalysisRuleSet>..\..\CodeAnalysis.ruleset</CodeAnalysisRuleSet>
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug iOS|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug iOS\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='iOS Debug|AnyCPU'">
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='iOS Release|AnyCPU'">
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Intergraph.SPC.Shared.Data">
<HintPath>..\..\..\PathToCode\Source\Shared\Shared.Data\bin\Shared.Data.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise />
</Choose>
<ItemGroup>
<ProjectReference Include="..\..\Mobile.Client\Mobile.Client\Mobile.Client.csproj" />
<ProjectReference Include="..\..\Mobile.TokenGenerator\Mobile.TokenGenerator.csproj" />
<ProjectReference Include="..\Mobile.Tests.Helpers\Mobile.Tests.Helpers.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="icons\mac\cell-SwitchCell-16~dark~sel%402x.png"/>
.......lots of content tags trimmed for readability.......
<Content Include="icons\win\view-WebView-16.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>16.11.0</Version>
</PackageReference>
<PackageReference Include="Moq">
<Version>4.13.1</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>3.8.3</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>3.8.3</Version>
</PackageReference>
<PackageReference Include="sqlite-net-pcl">
<Version>1.9.172</Version>
</PackageReference>
<PackageReference Include="SQLiteNetExtensions">
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
I'm on Microsoft Visual Studio Professional 2022 (64-bit) - Version 17.13.5
If I write regular unit tests that don't target android they will execute. I've tried making new solutions and use different versions of things, but once I target android34.0 nothing works anymore. Any thoughts/ideas as to why this is or where I can look would be very helpful. Thanks in advance!
Your unit test project shouldn't target net8.0-android
. Instead, change it to .NET 8.0
(net8.0
). However, this will cause another issue: since your test project is referencing your MAUI project, and the MAUI project targets net8.0-android
, the target frameworks between the two won't match.
To fix this issue, follow the steps below:
In your MAUI project, add net8.0
to the target frameworks:
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
To allow your MAUI project to compile as a DLL (which is required by the test project), conditionally set the OutputType
:
<OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>
For more information about setting up unit test projects in .NET MAUI, check out Gerald's video and sample repo:
📺 Video: https://www.youtube.com/watch?v=C9vIDLQwc7M
📁 GitHub Repo: https://github.com/jfversluis/MauixUnitTestSample