dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

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

Open santo998 opened 4 days ago

santo998 commented 4 days ago

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-*) ```xml 0.14.8 net8.0-android;net8.0-ios;net8.0-maccatalyst $(TargetFrameworks);net8.0-windows10.0.19041.0 true true enable 11.0 13.1 21.0 10.0.17763.0 10.0.17763.0 6.5 true MSBuild:Compile MSBuild:Compile ```

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

OvrBtn commented 3 days ago

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

santo998 commented 3 days ago

@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?

PureWeen commented 3 days ago

@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 commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

We only use netstandard2.0 cos it works everywhere.

mattleibow commented 3 days ago

OK, thanks!

I created a PR to report an error: https://github.com/dotnet/maui/pull/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.