Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
santo998 opened this issue Nov 19, 2024 · 8 comments · May be fixed by #25993
Open

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

santo998 opened this issue Nov 19, 2024 · 8 comments · May be fixed by #25993
Assignees
Labels
area-setup Installation, setup, requirements, maui-check, workloads, platform support migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending

Comments

@santo998
Copy link

santo998 commented Nov 19, 2024

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

@santo998 santo998 added the t/bug Something isn't working label Nov 19, 2024
@OvrBtn
Copy link

OvrBtn commented Nov 19, 2024

When you update MAUI nugets from 8 to 9 version you also have to change the .net version in .csproj from net8.0 to net9.0. Refer to docs for more details https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#upgrade-from-net-8-to-net-9

@mattleibow mattleibow added s/needs-info Issue needs more info from the author area-setup Installation, setup, requirements, maui-check, workloads, platform support migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert and removed area-setup Installation, setup, requirements, maui-check, workloads, platform support labels Nov 19, 2024
@santo998
Copy link
Author

@OvrBtn so, can't I update to MAUI 9 using .NET 8?

Then, shouldn't developers specify that MAUI 9 nuget requires .net 8, so it would give me an error when trying updating it?

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Nov 19, 2024
@PureWeen PureWeen changed the title Missing namespaces after updating to MAUI 9 Improve error message when users are referencing a .NET 9 NUGET from a .NET 8 TFM Nov 19, 2024
@PureWeen PureWeen removed t/bug Something isn't working s/needs-attention Issue has more information and needs another look labels Nov 19, 2024
@PureWeen PureWeen added this to the .NET 9 Servicing milestone Nov 19, 2024
@PureWeen
Copy link
Member

@OvrBtn so, can't I update to MAUI 9 using .NET 8?

Then, shouldn't developers specify that MAUI 9 nuget requires .net 8, so it would give me an error when trying updating it?

Correct, I've updated the title of this issue

We should really throw a better exception when users are trying to reference net9 nugets inside a net8 project

@mattleibow
Copy link
Member

Another option here is to actually drop netstandard and use net47 or something for the IDE only? In our targets we can use net9.0 in apps and net4x in the IDE.

We lose the netstandard, but that is something we actually want, right?

@Redth @PureWeen @mgoertz-msft @mauroa @jonathanpeppers @dellis1972 any thoughts on this?

@dellis1972
Copy link
Contributor

Another option here is to actually drop netstandard and use net47 or something for the IDE only? In our targets we can use net9.0 in apps and net4x in the IDE.

We lose the netstandard, but that is something we actually want, right?

@Redth @PureWeen @mgoertz-msft @mauroa @jonathanpeppers @dellis1972 any thoughts on this?

Not sure I get how using netstandard for the sdk stuff is related to this issue?

@mattleibow
Copy link
Member

I can solve the problem by removing netstandard from the nuget package and instead building for net47. Does the Android workload have netstandard2.0 build tasks, or does it multitarget net8.0 and net4x?

I can either write a complex logic to detect a scenario where the user installed newer nugets into an older project - like maui 9 into net8 and then throw an error. Or, we can let NuGet install fail with a useful error message.

@dellis1972
Copy link
Contributor

We only use netstandard2.0 cos it works everywhere.

@mattleibow
Copy link
Member

OK, thanks!

I created a PR to report an error: #25993

@Redth should I investigate dropping netstandard and adding netfx as a TFM for msbuild tasks? That will be more work and require more changes. aka: scary But is maybe more correct and then NuGet does the real TFM work.

@samhouts samhouts added platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-setup Installation, setup, requirements, maui-check, workloads, platform support migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

6 participants