Skip to content

Improve error message when users are referencing a .NET 9 NUGET from a .NET 8 TFM #25970

@santo998

Description

@santo998

Description

In a class under my Windows platform folder, the following types are missing:
Microsoft.UI.Xaml.Application
Microsoft.UI.Xaml.UnhandledExceptionEventArgs

This happened after updating these packages:
Microsoft.Maui.Controls 8.0.92 → 9.0.10
Microsoft.Maui.Controls.Compatibility 8.0.92 → 9.0.10

This is my .csproj (targeting net8.0-*)
<Project Sdk="Microsoft.NET.Sdk">
	
	<!-- Versión -->
	<PropertyGroup>
		<VersionPrefix>0.14.8</VersionPrefix>
		<!--<VersionSuffix Condition="'$(DesignTimeBuild)' != 'true' OR '$(BuildingProject)' == 'true'">beta-$([System.DateTime]::UtcNow.ToString(yyyyMMdd-HHmmss))</VersionSuffix>-->
	</PropertyGroup>

	<PropertyGroup>
		<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
		<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
		<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
		<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>
		<ImplicitUsings>enable</ImplicitUsings>

		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
		<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
		<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
		<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
		<AssemblyVersion></AssemblyVersion>
		<FileVersion></FileVersion>
	</PropertyGroup>

	<!-- Android -->
	<ItemGroup Condition="$(TargetFramework.StartsWith('net8.0-android')) != true">
		<Compile Remove="**\Android\**\*.cs" />
		<None Include="**\Android\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
	</ItemGroup>

	<!-- Both iOS and Mac Catalyst -->
	<ItemGroup Condition="$(TargetFramework.StartsWith('net8.0-ios')) != true AND $(TargetFramework.StartsWith('net8.0-maccatalyst')) != true">
		<Compile Remove="**\MaciOS\**\*.cs" />
		<None Include="**\MaciOS\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
	</ItemGroup>

	<!-- iOS -->
	<ItemGroup Condition="$(TargetFramework.StartsWith('net8.0-ios')) != true">
		<Compile Remove="**\iOS\**\*.cs" />
		<None Include="**\iOS\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
	</ItemGroup>

	<!-- Mac Catalyst -->
	<ItemGroup Condition="$(TargetFramework.StartsWith('net8.0-maccatalyst')) != true">
		<Compile Remove="**\MacCatalyst\**\*.cs" />
		<None Include="**\MacCatalyst\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
	</ItemGroup>

	<!-- Windows -->
	<ItemGroup Condition="$(TargetFramework.Contains('-windows')) != true">
		<Compile Remove="**\Windows\**\*.cs" />
		<None Include="**\Windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
	</ItemGroup>

	<ItemGroup>
		<PackageReference Include="CommunityToolkit.Maui" Version="9.1.1" />
		<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
		<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.10" />
		<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.10" />
		<PackageReference Include="Plugin.Maui.Audio" Version="3.0.1" />
	</ItemGroup>

	<ItemGroup>
		<MauiXaml Update="src\Vistas\BasePage.xaml">
			<Generator>MSBuild:Compile</Generator>
		</MauiXaml>
		<MauiXaml Update="src\Vistas\TareasPreviasBasePage.xaml">
			<Generator>MSBuild:Compile</Generator>
		</MauiXaml>
	</ItemGroup>

	<ItemGroup>
		<Folder Include="src\Platforms\MaciOS\" />
	</ItemGroup>

	<ItemGroup>
	  <ProjectReference Include="..\Amsoft.Base.DA\Amsoft.Base.DA.csproj" />
	  <ProjectReference Include="..\Amsoft.Base\Amsoft.Base.csproj" />
	</ItemGroup>

</Project>

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.92 SR9.2

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

Labels

area-setupInstallation, setup, requirements, maui-check, workloads, platform supportmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertp/0Current heighest priority issues that we are targeting for a release.platform/windowspotential-regressionThis issue described a possible regression on a currently supported version., verification pending

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions