question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build MAUI library targeting .NET6 should have a Platforms folder (like for Windows, Android, iOS, Tizen)

See original GitHub issue

Description

Hello,

I want to add UnitTest to my MAUI project. What I need to do is to add “.NET6.0” to the target frameworks.

I followed https://www.youtube.com/watch?v=C9vIDLQwc7M A video of our famous Gerald Versluis 😃

Previously I had this:

<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' != 'net7.0'">Exe</OutputType>

If I had net.7.0; I have an error while registering my services : the compiler is looking for MyServiceImplementation in a Platforms/PlatformNameHere and it doesn’t find any.

Maybe we should be able to create a folder “default” or “classic” or “core” or “base” i don’t know. Where you can declare service that are used as fallback service when no platform specific service is found. Or it could also be used when targeting .NET only instead of .NET Android .NET iOS etc.

image image

Look the last screenshot : it finds an implementation for each platform except the classic one. I don’t want to include the MyServiceNET7 into the assembly MauiAndroid where I already have MyServiceNET7Android.

Public API Changes

No public API changes: only improvment

Intended Use-Case

I want to be able to unit test my MAUI project with ease

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aritchiecommented, Oct 14, 2022

@nk53 All other code outside of Platforms can be compiled as NET6 and add net60; to your <TargetFrameworks>. If you want a folder that is specific ONLY to net6, you can add the following to your csproj:

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
    <Compile Include="Platforms\Net60\**\*.cs" />
</ItemGroup>
1reaction
drasticactionscommented, Oct 14, 2022

IMO “net7.0” isn’t a “fallback”, it’s a standard platform. The code where you’re adding services could be run on “net7.0”, which includes apps like console apps. You could wrap that call in a platform directive so it wouldn’t be run on net7.0 and only on the platforms and you wouldn’t need to write the implementation.

IMO this feels more like a misunderstanding of how to lay out code rather than something that would need yet another abstraction within MAUI to handle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Target multiple platforms from .NET MAUI single project
A single shared project that can target Android, iOS, macOS, Tizen, and Windows. A simplified debug target selection for running your .NET MAUI...
Read more >
Configure multi-targeting - NET MAUI
Learn how to configure multi-targeting in a .NET MAUI app, based on your own filename and folder criteria.
Read more >
Build Windows apps with .NET MAUI
NET MAUI, you can develop apps that can run on Windows, Android, iOS, macOS, and Samsung Tizen from a single shared code-base.
Read more >
Troubleshoot known issues - .NET MAUI
Learn about .NET MAUI known issues and troubleshooting you can do to resolve these issues.
Read more >
.NET MAUI Tutorial for Beginners - Build iOS, Android, macOS ...
Let's start our journey together to build beautiful native multi- platform apps with . NET MAUI, C#, . NET, and Visual Studio!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found