Is the conditional compilation option changed in VS 2022 17.5.2?

perfect code 271 Reputation points

I used conditional compilation in my last project and it worked very well.

Today I try to use it too, but the compiler doesn't recognise my condition that I added under Properties -> Build-> General

User's image

For example, if I want to use my MAUI input as a condition in the code, the compiler does not recognise it!

User's image

Has anything changed in the meantime here in this area?



There are three projects involved: P_1, P_2 and P3_. P_1 is a MAUI project and P_3 is a Blazor Server project. In P_2 I have common classes. To be able to differentiate platform specific code, I have added MAUI for conditional compilation in P_1. With this, I can then ask for MAUI in P_2 and execute platform-specific code from either MAUI or Blazor Server accordingly.

This worked quite well in the previous project, now I can't get it to work.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,570 questions
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,832 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,188 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 67,781 Reputation points Microsoft Vendor


    I test it in VS 2022 17.5.1, it is working. If this issue just happened in the 17.5.2.

    If you update from previous version to the 17.5.2 and your VS version is enterprise or professional, you can rollback to previous version.

    Please see this document. How can I rollback?

    Or download previous version directly,

    If your VS version is Community, please Report a problem with the Visual Studio product or installer

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Justin Strawther 0 Reputation points

    I encountered this issue too, and the cause turned out to be due to my confusion about the difference between Solution Configurations and Project Configurations. The conditional compilation symbols are defined based on the Project Configurations. In the Configuration Manager, when I selected the Active Solution Configuration at the top, I noticed that some of my projects had the wrong Configuration value in the table below. Updating the project configurations to match the solution configuration solved the issue for me.

    0 comments No comments