Configuring a Build
two basic types of build configuration: Debug and Release .The default build configuration is Debug. can also specify a specific build platform to target, click onbuild platform dropdown and select a different platform or Configuration Manager…
the configuration and platform values are also used to determine what project directory path is created to store the executable. For example, a project with a configuration of Debug
and a platform of x86
would be found under Projects\MyProjectNameHere\MyProjectNameHere\bin\Debug\x86
Building your Code
pressF7, selecting Build->Build Solution Rebuild your project by pressing either F7 again (to recompile only the files with errors) or Ctrl+Alt+F7 (for a clean and complete rebuild).
There are two build tabbed windows in the results window below the editor: the Output window, ; and the Error List window
Reviewing the Error List
快速调出代码的行号: turn on line numbers by clicking in the Quick Launch (Ctrl+Q) bar in the upper-right, typing “line numbers” into it, and pressing Enter. UseCtrl+G to quickly jump to the line number where the error occurred.
Theerror is identified by a red “squiggle” underscore. Hover over it for additional details. Make the fix and it will go away, although you may introduce a new error with the correction. (This is called a “regression”.)
Reviewing Errors in Detail
Performing Static Code Analysis
“Static code analysis” is a fancy way of saying “automatically check my code for common problems that can lead to run-time errors or problems in code management”. Get in the habit of running it once you’ve cleaned up the obvious errors preventing build, and take some time to address the warnings it may produce. You’ll save yourself some headaches down the road, as well as learn a few code style techniques.Using Light Bulbs to Fix or Refactor Code
No quick options available here
will be displayed in the lower-left corner bezel of the IDE.Light bulbs are a productivity feature in Visual Studio.
In C++, when you add a new function to a header file, you’ll see a light bulb that offers to create a stub implementation of that function.
鼠标悬停在波浪线处,或者插入点在有波浪线附近时按下Ctrl+.,灯泡就会出现。
Debugging Your Running Code
pressing F5 or selecting Debug->Start Debugging
the Autos/Locals/Modules/Watch tabbed window and the Call Stack/Breakpoints/Exception Settings/Output tabbed window
pause the app by pressing Ctrl+Alt+Break (or click on the Pause button).
PressF5 to continue running the app (or click the Continue button).
stop your app by pressing Shift+F5 or by clicking the Stop button, or simply close the app’s main window (or command line dialog)
Setting Simple Breakpoints
(You do NOT need to rebuild a project after setting and removing breakpoints.)
Set a breakpoint by clicking in the far margin of the line where you want the break to occur, or select the line of code and press F9. When the code breaks, the marked line of code has not executed yet.
Setting Conditional Breakpoints
click in the margin to set a breakpoint, and then select the “cog” from the hover menu that appears. Breakpoint Configuration Experience in Visual Studio.
Inspecting Your Code at Run-time
Usethe Diagnostic Tools window in conjunction with the Watch window and breakpoints
Running Unit Tests
Unit tests are programs that exercise code paths in your app or service. Visual Studio installs the Microsoft unit testing frameworks for both managed and native code. Use a unit testing framework to create unit tests, run them, and report the results of these tests. Rerun unit tests when you make changes to test that your code is still working correctly. When you use Visual Studio Enterprise edition, you can run tests automatically after every build.
To get started, read Generate unit tests for your code with IntelliTest.
To learn more about unit tests in Visual Studio and how they can help you create better quality code, read Unit Test Basics.
See Also
Debugging in Visual Studio
Debugger Settings and Preparation
Debug 64-Bit Applications
Debugger Basics