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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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

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'.
@mattleibow mattleibow requested a review from a team as a code owner 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?

Comment on lines 29 to 31
<Error
Code="MA003"
Text="This version of .NET MAUI requires at least a TargetFramework of '$(_MauiMinimumTargetFrameworkString)', which is greater than the current TargetFramework '$(TargetFramework)'." />
Copy link
Member

Choose a reason for hiding this comment

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

Can we go ahead and setup this message for localization?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure we have that infrastructure. @tj-devel709 what can we localize?

Copy link
Member

Choose a reason for hiding this comment

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

We should at least create a <MauiError/> task and start putting these strings in .resx files. We have examples in the dotnet/android repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll have a look. But, that we can do in a separate PR and I can go through the targets and collect the errors, warnings and messages.

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

<None Include="nuget\**" Exclude="nuget\**\*.in.*" PackagePath="" Pack="true" />
<None Remove="nuget\**" />
<None Include="nuget\**" Exclude="nuget\**\*.in.*;nuget\**\net-windows\*" PackagePath="" Pack="true" />
<None Include="nuget\buildTransitive\net-windows\**" PackagePath="buildTransitive\net$(_MauiMinimumSupportedDotNetTfm)-windows$(MinimumWindowsTargetFrameworkVersion)" Pack="true" />
Copy link
Member

Choose a reason for hiding this comment

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

Can you add more context on what this change is doing?

@@ -3,7 +3,7 @@
<ImportGroup Condition="Exists('$(_MauiBuildTasksLocation)Microsoft.Maui.Controls.Build.Tasks.dll') and Exists('$(_MauiBuildTasksLocation)Microsoft.Maui.Resizetizer.dll')">

<!-- Microsoft.Maui.Core.props -->
<Import Project="$(_MauiBuildTasksLocation)net6.0-windows10.0.17763.0\Microsoft.Maui.Core.props" Condition="'$(_MauiTargetPlatformIsWindows)' == 'true'" />
<Import Project="$(_MauiBuildTasksLocation)net$(_MauiMinimumSupportedDotNetTfm)-windows$(MinimumWindowsTargetFrameworkVersion)\Microsoft.Maui.Core.props" Condition="'$(_MauiTargetPlatformIsWindows)' == 'true'" />
Copy link
Member

Choose a reason for hiding this comment

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

Ahh so we used to just keep this very low, now we're setting it to what we know to be the min supported version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready To Review
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
5 participants