问题
How do I debug a native code project from inside a managed code project? I am using C# to call C++ code and need to debug the C++ code. Otherwise, I must exit out of the project, open the C++ project, create a tester and then debug the code. This is horrible.
回答1:
Add your c++ project to the solution containing your C# code
In the C# project properties pages, under the debug tab
Check "Enable unmanaged code debugging"
If that doesn't work you also need to open the Options dialog from either the Debug or the Tools menu (in VS2017) and go to Debugging->General. Check the option
"Suppress JIT optimization on module load (Managed only)."
You will then be able to debug into your C++/CLI and C++ code. (This final tip comes from Kim Togo Andersen.)
回答2:
In the debugging options for visual studio you HAVE to specify the correct debugger type.
Open up the property dialog window for the project, and under the Configuration Properties select Debugging. For the Debugger Type option, select the property that applies:
This can be auto, or mixed. I prefer mixed as it is explicitly stating you want both managed and native debugging.
As a side note, you can pick native only, but you won't be able to set a breakpoint in managed code. I'm not sure if this is an issue for you or not.
If you pick managed only, you obviously won't hit any breakpoints in native code.
来源:https://stackoverflow.com/questions/6738006/how-do-i-debug-a-native-code-project-from-inside-a-managed-code-project-c-c