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

Add options for specifying a minimum workload version requirement #25993

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Nov 20, 2024

Description of Change

If we detect that you have installed .NET MAUI NuGet packages into an SDK which has some old version of the .NET MAUI workload, then we will fail the build.

The error code is MA003 and there is a property to skip this warning as well: $(SkipCheckForMauiMinimumSupportedWorkloadVersion)

Errors will look like:

error MA003: The current .NET MAUI package version 'NUGET_VERSION' requires the .NET MAUI workload version to be at least 'MIN_WORKLOAD_VERSION'. The current .NET MAUI workload version is 'CURRENT_WORKLOAD_VERSION'.

error MA003: The current .NET MAUI package version '9.0.10-dev' requires the .NET MAUI workload version to be at least '9.0.0'. The current .NET MAUI workload version is '8.0.83'.

Issues Fixed

Fixes #25970

@mattleibow mattleibow requested a review from a team as a code owner November 20, 2024 17:24
@mattleibow mattleibow requested review from Eilon and rmarinho November 20, 2024 17:24
@mattleibow mattleibow changed the title Add a MSBuild error for when .NET MAUI is installed as netstandard2.0 instead of the correct TFM [Option 1] Add a MSBuild error for when .NET MAUI is installed as netstandard2.0 instead of the correct TFM Nov 20, 2024
@mattleibow mattleibow marked this pull request as draft November 20, 2024 17:25
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @dsplaisted can comment on the general problem here? Targeting .NET 9 MAUI packages from a .NET 8 project would certainly default to netstandard2.0 if those exist.

@mattleibow why does Microsoft.Maui.Controls have netstandard2.0 assemblies inside at all? That is needed for MSBuild tasks inside Visual Studio, so you could simply have a copy of those in the Microsoft.Maui.Controls.Build.Tasks package? They shouldn't be referenced by customer projects, just used by the MSBuild tasks?

@rolfbjarne
Copy link
Member

Wild idea: provide a net6.0 version of the assemblies that has:

[Obsolete ("This version of MAUI requires at least a TargetFramework of ...", IsError = true)]

on every API.

@mattleibow mattleibow changed the title [Option 1] Add a MSBuild error for when .NET MAUI is installed as netstandard2.0 instead of the correct TFM Add options for specifying a minimum workload version requirement Nov 20, 2024
@mattleibow mattleibow marked this pull request as ready for review November 21, 2024 05:28
@PureWeen PureWeen added this to the .NET 9 SR1.1 milestone Nov 21, 2024
@jonathanpeppers
Copy link
Member

jonathanpeppers commented Nov 21, 2024

@mattleibow why does Microsoft.Maui.Controls have netstandard2.0 assemblies inside at all?

Do we know the answer to this question? MSBuild won't even know how to find these assemblies unless you use AppDomain.AssemblyResolve. So, we probably have a copy of the netstandard2.0 assemblies in the Microsoft.Maui.Controls.Build.Tasks package.

@PureWeen PureWeen modified the milestones: .NET 9 SR1.1, .NET 9 SR2 Nov 25, 2024
- Installing a .NET 9 MAUI package into a .NET 8 project
- Installing a .NET 9 MAUI package into a very old .NET 9 installation

To skip this check, set $(SkipCheckForMauiMinimumSupportedWorkloadVersion) to true.
Copy link
Member

@rmarinho rmarinho Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need some documentation heads up @davidortinau @rachelkang .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to advertise this option? It will only cause pain, and I just added this as a failsafe just in case.

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test where we try to install this on a machine with net8 sdk only? I know it might be tricky. but I think that will cover this edge case works.

Also I think the message needs to be localized.

@PureWeen
Copy link
Member

PureWeen commented Dec 4, 2024

/rebase

If we detect that you have installed .NET MAUI into a TFM which is not
found in the package, then we will fail the build.

The error code is MA003 and there is a property to skip this warning as
well:

Errors will look like:
- error MA003: This version of .NET MAUI requires at least a
  TargetFramework of 'net9.0-windows10.0.19041.0', which is greater
  than the current TargetFramework 'net8.0-windows10.0.19041.0'.
- error MA003: This version of .NET MAUI requires at least a
  TargetFramework of 'net9.0-ios', which is greater than the current
  TargetFramework 'net8.0-ios'.
- error MA003: This version of .NET MAUI requires at least a
  TargetFramework of 'net9.0-maccatalyst17.0', which is greater than
  the current TargetFramework 'net8.0-maccatalyst17.0'.
This happens mostly in the maui repo, but also may happen if the
build is not using workloads. This is not really possible outside
of the maui repo source build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve error message when users are referencing a .NET 9 NUGET from a .NET 8 TFM
7 participants