maui: .NET8 - UseMauiEssentials not working on project targeting net6.0
Description
I updated Visual Studio 22 Windows to Version 17.8. This has installed the .NET8 SDK on my system.
A class library that includes <UseMauiEssentials> does not build.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'Connectivity' does not exist in the current context
Error CS0234 The type or namespace name 'Maui' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
I am then told the solution is to install the Xamarin.Essentials package which is not compatible with any .NET SDK project.
The project builds if:
- I create a
global.jsonand point to .NET7 or .NET6 SDKs (which had to be reinstalled as it seems .NET8 nukes those upon install) - I change the target project to
net7.0
Steps to Reproduce
- Create a new class library targeting net6.0
- Edit project file to look like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UseMauiEssentials>true</UseMauiEssentials>
</PropertyGroup>
</Project>
- Add the following code to
Class1.cs
using Microsoft.Maui.Networking;
namespace MauiEssentialBug {
public class Class1 {
public void Foo() {
var x = Connectivity.NetworkAccess;
System.Diagnostics.Debug.WriteLine($"Foo = {x}");
}
}
}
- Fails to compile
Link to public reproduction project repository
https://github.com/projectgoav/MauiEssentialsBug
Version with bug
Unknown/Other
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows
Affected platform versions
.NET8 / VS22 17.8
Did you find any workaround?
Upgrading the project to net7.0 Adding a global.json to point to .NET7 SDK
Relevant log output
No response
About this issue
- Original URL
- State: open
- Created 8 months ago
- Reactions: 2
- Comments: 18 (3 by maintainers)
.NET 6 is no longer supported https://dotnet.microsoft.com/en-us/platform/support/policy/maui
If you need to use .NET 6 for mobile, please use an older SDK.
It seems to be a separate support cycle altogether due being linked to the native platforms (iOS/Android):
.NET support cycle: https://dotnet.microsoft.com/en-us/platform/support/policy/maui MAUI support cycle: https://dotnet.microsoft.com/en-us/platform/support/policy/maui
Which is a bit of an issue considering .NET and MAUI version are linked in .NET 6 (unless there is a workaround to that?)
With MAUI/.NET version being separated into NuGet packages from .NET 7 onward there shouldn’t be too much of an issue for the future, but it’s still an issue for earlier yet still supported platforms like .NET 6…
Somewhat off-topic, but as any progress for .NET 6 is rather unlikely at this point, I have opened #19160 and a Developer Community request. Please give a thumbs up or upvote to help push for changing the support policy for .NET MAUI to be part of the same LTS cycle.
So does this mean that .NET MAUI exists outside of the LTS support policy that applies the rest of the framework? That seems incredibly counterintuitive and shortsighted. Why even bother having an LTS edition if developers cannot rely on having their production applications work for the duration.