'How can i debug my code when i'm targeting multiple versions of .net?

I'm trying to target multiple .net framework versions with the built in preprocessor directives but i can't debug the targeted version of my code because that part of my code is cannot be hit during debug.

Here's my code:

   private static void WriterTask(string processName, byte[] byteArray)
   {
#if NET_46
        Task.Run(() =>
        {
            FileWriter(_path, processName, byteArray);
        });
#elif NET_35
        FileWriter(_path, processName, byteArray);
#endif
   }


Solution 1:[1]

If you are debugging an application via Visual Studio, you need to check the framework version you are using to launch it. The corresponding setting can be found in the launch button dropdown.

Here is how this setting looks like in VS2019 for my application, which is targeting both .NET Framework 4.5 and .NET Core 3.0: enter image description here On the screenshot, the .NET Framework 4.5 is selected, but I can switch to .NET Core 3.0 by selecting the corresponding item in the menu.

My application contains a few #if NET45 sections, and they can be debugged properly in this case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1