dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

#if WINDOWS does not compile #8382

Open janseris opened 2 years ago

janseris commented 2 years ago

Description

When I select Windows Machine, the code does not compile. Expected behavior: When Windows Machine is selected to run the MAUI App, Visual Studio compiles the app for Windows.

image

The issue is not fixed when selecting .net6.0-windows from the dropdown in the code editor (I thought it would be fixed). IntelliSense syntax check passes but build error is still there and the application cannot be started. Clean/Rebuild does not help. Deleting bin and obj folders and then rebuilding does not help.

image

Steps to Reproduce

MauiApp11.zip

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10

Did you find any workaround?

No response

Relevant log output

No response

Eilon commented 2 years ago

Hmm I think we've seen issues like this before. I don't recall the conclusion.

janseris commented 2 years ago

@Eilon I saw #elif WINDOWS not working issue with no solution and I have that issue as well (happens when I write #if ANDROID #elif WINDOWS with string variable declarations/definitions inside similarly to the example in this issue)

https://github.com/dotnet/maui/issues/6815#issuecomment-1136147134 <-- the #elif WINDOWS issue

kristinx0211 commented 2 years ago

repro this issue on windows.

iron4548 commented 2 years ago

I'm having this issue as well. I'm running Windows 10.

With target OS set to 'Net 6.0' the code is greyed out in the NET 6.0 class library as shown below. The NET 6.0 console application is currently selected as the startup project and has reference to the NET 6.0 class library.

image

If I change the target OS to: 'net6.0-windows10.0.19041.0', then the code is no longer greyed out but it still doesn't get hit when I run the NET 6.0 console application on Windows (Debug mode). I've added a breakpoint before the #if WINDOWS and the breakpoint does get hit, but the code within the #if block doesn't get called.

image

I also tried changing the Target OS to 'Windows' from 'None' (on the NET 6.0 Console App) and that made no difference.

image

This is what my solution looks like

image

Any idea what I'm doing wrong?

Happy to provide more info where needed.

UPDATE

This is what the conditional complication symbols looks like for the NET 6.0 class library if this is relevant. They are the default values (unchanged since the creation of the class lib)

image

Adding WINDOWS to net6.0-windows10.0.19041.0 doesn't work either. But adding it to net6.0 does (but obviously affects all platforms)

image

salarcode commented 2 years ago

I've provided a solution in here

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Windows 11 with below Project: MauiApp11.zip

image

AlexeyStarkov commented 1 year ago

Facing a similar issue on VS for Mac (17.5.6 (build 3)) but with #elif IOS || MACCATALYST. It doesn't switch to elif code when iPhone is selected as target. It means "if" code (Android in my case) is always highlighted.