Search code examples
.netvb.netvisual-studio

In Visual Studio 2022, the `#IF DEBUG` pre-compiler constant is True when publishing. How can I fix this?


I am using VB.NET and trying to publish to a directory. However, when I hit "Publish Now", I have code that only runs when #IF DEBUG is True. On Visual Studio, when I switch to Release mode and build, the code doesn't run. How do I set it so on publish, it uses Release mode and not Debug mode?

I verified Release mode does not have DEBUG constant checked and running Release mode locally is working correctly. Only on "Publish Now" does it use DEBUG mode.

Screenshot showing DEBUG constant is disabled in Release config.

Image


Solution

  • After you modify the configuration of the Release Mode in Project Property Compile page, you will also need to select the solution configured as Release and then publish.

    enter image description here