How to publish from Visual Studio to Docker in Debug mode

I have a .NET Core dll that I want to publish to a Docker repository in Debug mode. Unfortunately, changing the configuration in the publish screen has no effect, nor does manually editing the pubxml publish profile file. No matter what I do, Visual Studio always compiles in Release mode.

How can I force VS to compile and deploy in debug mode?

Source: StackOverflow