I can attach VS2022 code to MSFS2020 and do the debugging step by step.
However, after hitting the stop button in VS2022, there are usually two cases of crashing:
1, the MSFS2020 suddenly crashes after hitting the button.
2, the MSFS2020 can still run but will crash after I tried to build the package again in MSFS2020.
May I ask if I have any wrong configurations? Thanks!
Just like @Boris said, you must pass the -AllowDebugger command-line argument to the sim before launching. I found a straightforward way to launch the sim with the argument passing, and it works for the MS Store version. I honestly didn’t know about it until now that I made a quick reseach on Google. For the Steam version, you can find where the executable is (because it is accessible), and in the same way, locate the core app files directory in the Command Prompt, and type flightsimulator.exe -AllowDebugger.
For the MS Store version, run Windows Terminal (cmd.exe mode) or the Command Prompt on your system. Then type the command, like in the shot below, and press Enter.
Actually, I saw the suggestion that we should pass this parameter, otherwise, we cannot debug the code. However, I found that I still can debug with occasionally crashing, so I did not pass the parameter…