Some Projects Have Trouble Loading Please Review the Output for More Details
This browser is no longer supported.
Upgrade to Microsoft Border to take advantage of the latest features, security updates, and technical support.
Make lawmaking piece of work in Visual Studio
Visual Studio provides a powerful integrated set of project build and debugging tools. In this article, find out how Visual Studio tin aid you notice problems in your code using build output, code assay, debugging tools, and unit tests.
You've figured out the editor and created some code. Now, you lot want to make sure the lawmaking works properly. In Visual Studio, as with most IDEs, there are 2 phases to making code work: building the code to grab and resolve project and compiler errors, and running the code to find run-fourth dimension and dynamic errors.
Build your code
There are two basic types of build configuration: Debug and Release. The Debug configuration produces a slower, larger executable that allows for a richer interactive run-time debugging feel. The Debug executable should never exist shipped. The Release configuration builds a faster, optimized executable that'due south appropriate to ship (at least from the perspective of the compiler). The default build configuration is Debug.
The easiest way to build your project is to press F7, but you tin likewise outset the build past selecting Build > Build Solution from the main menu.
Yous tin notice the build procedure in the Output window at the lesser of the Visual Studio UI. Errors, warnings, and build operations are displayed here. If you have errors (or if y'all have warnings above a configured level), your build fails. You tin can click on the errors and warnings to go to the line where they occurred. Rebuild your project by either pressing F7 again (to recompile only the files with errors) or Ctrl+Alt+F7 (for a clean and complete rebuild).
In that location are 2 tabbed windows in the results window beneath the editor: the Output window, which contains the raw compiler output (including fault letters); and the Fault List window, which provides a sortable and filterable list of all errors and warnings.
When build succeeds, you see results like this in the Output window:
Review the Error Listing
Unless y'all've fabricated no modifications to code you've previously and successfully compiled, you probably have an error. If you're new to coding, you probably accept lots of them. Errors are sometimes obvious, such equally a simple syntax fault or incorrect variable proper name, and sometimes they are difficult to sympathize, with only a cryptic lawmaking to guide you. For a cleaner view of the issues, navigate to the bottom of the build Output window, and click the Error Listing tab. This takes you to a more organized view of the errors and warnings for your project, and gives you some extra options also.
Click on the error line in the Error List window to jump to the line the mistake occurs in. (Or plough on line numbers by pressing Ctrl+Q, typing line numbers, and then choosing Plow line numbers on or off from the results. This is the fastest style to get to the Options dialog where you tin plow on line numbers.)
Press Ctrl+Yard to quickly jump to the line number where the error occurred.
The error is identified by a red "squiggle" underscore. Hover over information technology for additional details. Make the ready and it volition get away, although you may introduce a new mistake with the correction. (This is called a "regression".)
Walk through the fault list and address all the errors in your code.
Review errors in detail
Many errors may brand no sense to you, phrased as they are in the terms of the compiler. In those cases, you'll need additional information. From the Error List window, yous can do an automatic Bing search for more data on the mistake or warning. Right-click on the respective entry line and select Testify Error Help from the context menu, or click on the hyperlinked fault code value in the Code column of the Error List.
Depending on your settings, either your web browser displays the search results for the error lawmaking and text, or a tab opens inside Visual Studio and shows the results of the Bing search. The results are from many different sources on the Internet, and not all may be helpful.
Use code analysis
Code analyzers await for mutual code problems that tin lead to run-time errors or problems in lawmaking management.
C# and Visual Bones code assay
Visual Studio includes a built-in prepare of .NET Compiler Platform analyzers that examine C# and Visual Bones lawmaking as you blazon. You tin can install additional analyzers as a Visual Studio extension, or as a NuGet bundle. If rule violations are found, they are reported both in the Error List and in the code editor every bit a squiggle under the offending code.
C++ lawmaking analysis
To analyze C++ lawmaking, run static code assay. Get in the habit of running it once you've cleaned up the obvious errors that prevent a successful build, and take some time to accost the warnings information technology may produce. You'll relieve yourself some headaches down the road, and you may acquire a few lawmaking style techniques.
Printing Alt+F11 (or select Analyze > Run Code Analysis on Solution from the tiptop menu) to start static code analysis.
Any new or updated warnings appear in the Error List tab at the bottom of the IDE. Click on the warnings to jump to them in code.
Use Quick Deportment to fix or refactor code
Quick Actions, available from the light bulb or screwdriver icon, let you refactor lawmaking inline. They are an like shooting fish in a barrel way to set up common warnings quickly and effectively in C#, C++, and Visual Bones code. To access them, correct-click on a warning squiggle and select Quick Actions and refactorings. Or, when your cursor is on the line with the colored squiggle, press Ctrl+. or select the light bulb, error calorie-free seedling, or screwdriver icon in the margin. Y'all'll come across a list of possible fixes or refactorings you tin apply to that line of lawmaking.
Quick Actions tin can be used wherever code analyzers determine there'due south an opportunity to fix, refactor, or meliorate your code. Click on whatsoever line of code, right-click to open the context menu, and select Quick Actions and refactorings. If refactoring or improvement options are bachelor, they are displayed. Otherwise, the message No quick deportment bachelor here displays in the lower-left corner of the IDE.
With experience, you tin can speedily utilize the arrow keys and Ctrl+. to check for easy refactoring opportunities and clean up your lawmaking!
Run Code Cleanup
Visual Studio provides on-demand formatting of your C# code file, including lawmaking mode preferences, through the Code Cleanup push button at the bottom of the editor.
In add-on to formatting your file for spaces, indents, et cetera, Code Cleanup likewise applies a set up of code style conventions that you lot ascertain. Your preferences for each lawmaking style are read from the EditorConfig file, if you have one for the projection, or from the code style settings in the Options dialog box.
Debug your running code
At present that you've successfully built your code and performed a trivial clean up, run it by pressing F5 or selecting Debug > Start Debugging. This starts your app in a debug environs and so yous can find its behavior in detail. The Visual Studio IDE changes while your app is running: the Output window is replaced by two new ones (in the default window configuration), the Autos/Locals/Watch tabbed window and the Telephone call Stack/Breakpoints/Exception Settings/Output tabbed window. These windows take multiple tabs that let you to inspect and evaluate your app's variables, threads, call stacks, and various other behaviors as it runs.
Stop your app past pressing Shift+F5 or past clicking the Stop push. Or, you can just close the app's main window (or command-line dialog).
If your code ran perfectly and exactly equally expected, congratulations! Nevertheless, if it stops responding, or crashed, or gave you some foreign results, you lot'll need to find the source of those problems and fix the bugs.
Set simple breakpoints
Breakpoints are the nearly basic and essential feature of reliable debugging. A breakpoint indicates where Visual Studio should suspend your running lawmaking then you can have a look at the values of variables, or the behavior of retention, or whether or not a branch of lawmaking is getting run. You lot don't need to rebuild a projection subsequently setting and removing breakpoints.
Fix a breakpoint past clicking in the far margin of the line where you lot desire the break to occur, or press F9 to ready a breakpoint on the current line of code. When you run your code, it volition break (or intermission) before the instructions for this line of code are executed.
Common uses for breakpoints include:
-
To narrow down the source of a crash or unresponsive program, besprinkle breakpoints throughout and around the code of the method call you lot recall is causing the failure. As you run code in the debugger, remove and so reset the breakpoints closer together until you lot find the offending line of code. Run into the adjacent section to learn how to run lawmaking in the debugger.
-
When y'all introduce new code, set a breakpoint at the beginning of it, and run the lawmaking to make sure it is behaving as expected.
-
If you lot've implemented a complicated beliefs, set breakpoints for the algorithmic code so you tin can audit the values of the variables and information when the program breaks.
-
If y'all're writing C or C++ code, apply breakpoints to terminate the code so you can inspect accost values (look for Zip) and reference counts when debugging for memory-related failures.
For more than information well-nigh using breakpoints, read Using breakpoints.
Inspect your code at run-time
When your running lawmaking hits a breakpoint and pauses, the line of code marked in yellow (the current argument) has not executed yet. At this signal, you lot may want to execute the current statement and so inspect the changed values. You can employ several step commands to execute code in the debugger. If the marked code is a method call, yous can step into it past pressing F11. You can as well step over the line of code by pressing F10. For additional commands and details on how to pace through lawmaking, read Navigate code with the debugger.
In the preceding illustration, y'all tin can accelerate the debugger one statement past pressing either F10 or F11 (since there is no method call here, both commands have the same consequence).
While the debugger is paused, you can inspect your variables and call stacks to determine what is going on. Are the values in the ranges yous wait to see? Are calls beingness made in the correct order?
Hover over a variable to see its current value and references. If yous meet a value y'all didn't look, you lot probably take a bug in the preceding or calling code. For more in-depth debugging data, learn more virtually using the debugger.
Additionally, Visual Studio displays the Diagnostic Tools window, where you tin can notice your app's CPU and retentivity usage over time. Later on in your app development, you can use these tools to look for unanticipated heavy CPU usage or memory allocation. Use it in conjunction with the Sentinel window and breakpoints to decide what's causing unexpected heavy usage or unreleased resources. For more information, see Profiling characteristic bout.
Run unit tests
Unit of measurement tests are your first line of defense against code bugs considering, when washed correctly, they examination a single "unit" of code, typically a single function, and are easier to debug than your full program. Visual Studio installs the Microsoft unit testing frameworks for both managed and native code. Utilize a unit of measurement testing framework to create unit of measurement tests, run them, and report the results of these tests. Rerun unit of measurement tests when y'all make changes, to test that your code is nevertheless working correctly. With Visual Studio Enterprise edition, y'all can run tests automatically after every build.
To go 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 lawmaking, read Unit of measurement test nuts.
See also
- First look at the debugger
- Learn more about using the debugger
- Generate and set lawmaking
Feedback
Submit and view feedback for
Source: https://docs.microsoft.com/en-us/visualstudio/ide/find-and-fix-code-errors
0 Response to "Some Projects Have Trouble Loading Please Review the Output for More Details"
Post a Comment