Skip to main contentThis browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Install Hyper-V on Windows 10
In this articleEnable Hyper-V to create
virtual machines on Windows 10.
Check Requirements
The Hyper-V role cannot be installed on Windows 10 Home. Upgrade from Windows 10 Home edition to Windows 10 Pro by opening up Settings > Update and Security > Activation. For more information and troubleshooting, see Windows 10 Hyper-V System Requirements. Enable Hyper-V using PowerShell
If the command couldn't be found, make sure you're running PowerShell as Administrator. When the installation has completed, reboot. Enable Hyper-V with CMD and DISMThe Deployment Image Servicing and Management tool (DISM) helps configure Windows and Windows images. Among its many applications, DISM can enable Windows features while the operating system is running. To enable the Hyper-V role using DISM:
For more information about DISM, see the DISM Technical Reference. Enable the Hyper-V role through Settings
When the installation has completed you are prompted to restart your computer. Make virtual machinesCreate your first virtual machine FeedbackSubmit and view feedback for Skip to main content This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Tutorial: Learn to debug C# code using Visual Studio
In this articleApplies to: Visual Studio Visual Studio for Mac Visual Studio CodeThis article introduces the features of the Visual Studio debugger in a step-by-step walkthrough. If you want a higher-level view of the debugger features, see First look at the debugger. When you debug your app, it usually means that you are running your application with the debugger attached. When you do this, the debugger provides many ways to see what your code is doing while it runs. You can step through your code and look at the values stored in variables, you can set watches on variables to see when values change, you can examine the execution path of your code, see whether a branch of code is running, and so on. If this is the first time that you've tried to debug code, you might want to read Debugging for absolute beginners before going through this article. Although the demo app is C#, most of the features are applicable to C++, Visual Basic, F#, Python, JavaScript, and other languages supported by Visual Studio (F# does not support Edit-and-continue. F# and JavaScript do not support the Autos window). The screenshots are in C#. In this tutorial, you will:
PrerequisitesYou must have Visual Studio 2022 installed and the .NET desktop development workload. You must have Visual Studio 2019 installed and the .NET Core cross-platform development workload. If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free. If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features..., which opens the Visual Studio Installer. The Visual Studio Installer launches. Choose the .NET Core cross-platform development workload, then choose Modify. If you already have Visual Studio but the .NET desktop development workload isn't installed, go to Tools > Get Tools and Features..., which launches the Visual Studio Installer. In the Visual Studio Installer, choose the .NET desktop development workload, then choose Modify. Create a projectFirst, you'll create a .NET Core console application project. The project type comes with all the template files you'll need, before you've even added anything!
Create the applicationIn Program.cs, replace all of the default code with the following code:
Start the debugger!
Mostly, we use keyboard shortcuts here, because it's a fast way to execute debugger commands. Equivalent commands, such as toolbar or menu commands, are also noted.
Set a breakpoint and start the debugger
Navigate code and inspect data by using data tipsMostly, we use the keyboard shortcuts here, because it's a good way to get fast at executing your app in the debugger (equivalent commands such as menu commands are shown in parentheses).
Navigate code using Run to Click
Restart your app quicklyClick the Restart button in the Debug Toolbar (Ctrl + Shift + F5).When you press Restart, it saves time versus stopping the app and restarting the debugger. The debugger pauses at the first breakpoint that is hit by executing code. The
debugger stops again at the breakpoint you previously set inside the To rerun your app from the beginning in the debugger, select Ctrl+Shift+F5, or choose the Restart button in the Debug toolbar, or choose Debug > Restart from the menu bar.
Restart stops the debugger and then restarts it, in one step. When the debugger restarts, it will run to the first breakpoint, which is the breakpoint you previously set inside the Inspect variables with the Autos and Locals windows
The Autos and Locals windows show variable values while you're debugging. The windows are only available during a debug session. The Autos window shows variables used on the current line that the debugger is at and the preceding line. The Locals window shows variables defined in the local scope, which is usually the current function or method.
For more about the Autos and Locals windows, see Inspect variables in the Autos and Locals windows. Set a watch
You can specify a variable, or an expression, that you want to keep an eye on as you step through code—by adding it to the Watch window.
For more about the Watch window, see Watch variables with Watch windows. Examine the call stack
The Call Stack can help you understand the execution flow of your app, by showing the order in which methods and functions are getting called.
For more about the Call Stack, see How to: Examine the Call Stack. Change the execution flow
You can move the execution pointer to change the flow of your app while debugging.
By changing the execution flow, you can do things like test different code execution paths or rerun code without restarting the debugger. Warning Use this feature with care. You'll see a warning in the tooltip of the execution pointer about the possibility of unintended consequences. You might see other warnings, too. Moving the execution pointer can't revert your application to an earlier state. For more about the changing the execution flow, see Move the pointer to change the execution flow. Congratulations on completing this tutorial! Next stepsIn this tutorial, you've learned how to start the debugger, step through code, and inspect variables. You might want to get a high-level look at debugger features along with links to more information. FeedbackSubmit and view feedback for |