Running and Debugging
Build, run, and debug your .NET applications directly from the Solution Explorer.
Overview
C# Dev Tools integrates with VS Code's debugging and task system to provide a seamless development experience for .NET applications.
Building Projects
Build Commands
Right-click on a project or solution and select:
- Build: Compile the project and its dependencies
- Rebuild: Clean and then build the project
- Clean: Remove all build artifacts (bin/ and obj/)
Build Output
Build output appears in:
- The Terminal panel - Shows full build logs
- The Problems panel - Lists errors and warnings
- Status bar - Shows build progress
Keyboard Shortcuts
Ctrl+Shift+B
- Build the current project- Configure additional shortcuts in keyboard settings
Setting a Startup Project
The startup project is the project that runs when you press F5:
Set Startup Project
- Right-click on an executable project (console app, web app, etc.)
- Select Set as Startup Project
- The project name will appear in bold in the Solution Explorer
Multiple Startup Projects
To run multiple projects simultaneously:
- Configure launch.json for multiple configurations
- Or use VS Code's compound launch configurations
- Useful for running client and server projects together
Running Applications
Console Applications
To run a console application:
- Set it as the startup project
- Press
F5
to run with debugging - Or press
Ctrl+F5
to run without debugging
The application will run in the integrated terminal.
Web Applications
To run a web application (ASP.NET Core):
- Set it as the startup project
- Press
F5
to launch with debugging - The application will start and the browser will open automatically
The browser will navigate to the configured URL (usually https://localhost:5001).
Stopping Applications
To stop a running application:
- Click the Stop button in the debug toolbar
- Press
Shift+F5
- Close the terminal (for console apps)
Debugging
Starting a Debug Session
- Set breakpoints by clicking in the left margin of the editor
- Set the startup project
- Press
F5
to start debugging
The debugger will:
- Build the project if needed
- Launch the application
- Attach the debugger
- Stop at your breakpoints
Debug Features
While debugging, you can:
- Step Through Code: F10 (Step Over), F11 (Step Into), Shift+F11 (Step Out)
- Inspect Variables: Hover over variables or use the Variables panel
- Watch Expressions: Add expressions to the Watch panel
- Call Stack: View the call stack in the Call Stack panel
- Breakpoints: Manage breakpoints in the Breakpoints panel
Inline Debug Values
C# Dev Tools provides inline debug values that show variable values directly in your code:
- Variable values appear at the end of lines during debugging
- Changed values are highlighted
- Arrays and objects show their contents inline
Configure this feature in the extension settings.
Conditional Breakpoints
Set breakpoints that only trigger under specific conditions:
- Right-click on a breakpoint
- Select Edit Breakpoint
- Choose a condition type:
- Expression is true
- Hit count
- Log message
Launch Configurations
Viewing Launch Configuration
The extension automatically generates launch configurations:
- Open
.vscode/launch.json
- View the generated configurations
- Customize as needed
Program Arguments
To pass command-line arguments:
Method 1: Edit launch.json
{
"args": ["arg1", "arg2", "arg3"]
}
Method 2: Use Code Lens
Click the Code Lens above the Main
method to configure arguments.
Environment Variables
Set environment variables in launch.json:
{
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"MY_VAR": "value"
}
}
Running Tests
The Solution Explorer integrates with the Test Explorer:
- Right-click on a test project
- Select Run Tests
- Tests will execute and results will appear in the Test Explorer
See the Testing Integration section for more details.
Build Configurations
Debug vs Release
Switch between build configurations:
- Open the command palette (
Ctrl+Shift+P
) - Type "C# Solution Explorer: Select Build Configuration"
- Choose Debug or Release
Debug builds:
- Include debugging symbols
- Disable optimizations
- Enable assertions
Release builds:
- Exclude debugging symbols
- Enable optimizations
- Better performance
Custom Configurations
Create custom build configurations in your project files:
<PropertyGroup Condition="'$(Configuration)'=='CustomConfig'">
<!-- Custom configuration properties -->
</PropertyGroup>
Troubleshooting
Build Fails
If build fails:
- Check the Problems panel for errors
- Review the Terminal output for detailed messages
- Ensure all NuGet packages are restored
- Verify target framework is installed
Cannot Start Debugging
If debugging won't start:
- Ensure the startup project is set
- Check that launch.json is configured correctly
- Verify the project builds successfully
- Check for port conflicts (web applications)
Breakpoints Not Hit
If breakpoints aren't working:
- Build in Debug configuration
- Ensure you're debugging the correct process
- Check that the code file is part of the project
- Disable "Just My Code" if needed
Performance Issues
If builds or debugging is slow:
- Disable unnecessary extensions
- Exclude large folders from file watching
- Use Release configuration for non-debugging runs
- Close unused projects in the solution