maui: #elif WINDOWS doesn't work

Description

I want to create a service and use dependency injection.

It works on each platform except windows. First, #elif __WINDOWS__ wasn’t taken into account by Visual Studio (see screenshot below) image

Next, #elif WINDOWS was recognized by Visual Studio but not by the compiler as it tells me it can’t find the implementation of my service.

It should work and the documentation MUST (just my opinion, you’re the boss haha) be updated to tell to developpers what’s the difference between #if __ANDROID__ and #if ANDROID On the Microsoft documentation I saw both, it’s quite confusing. Even more when #if __WINDOWS__ doesn’t work while #if WINDOWS does. Edit: answer given here don’t use the double underscore.

Steps to Reproduce

  • create an interface inside the MAUI project
  • create an implementation of that interface inside each platforms folder
  • try to register the service inside MauiProgram.cs

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows (I’m using Visual Studio 17.2.0 Preview 6.0)

Affected platform versions

net6.0-windows10.0.19041

Did you find any workaround?

Yes !

I handle each platform and handle WINDOWS in the #else

But it’s a dirty hack because if the problem occurs on Tizen too, it cannot work

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 29 (15 by maintainers)

Commits related to this issue

Most upvoted comments

LOL I didn’t notice it was you @jfversluis : the famous Gerald from youtube!! 😆 I post some messages on your Youtube channel few days ago (Nicolas Krier) to say how much I love your content 😉

Glad to meet you here 😄

Adding this to .csproj file fixes the issue for me. Looks like WINDOWS is not defined

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
    <DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>