Run Configurations: debug any static method in Visual Studio, and more
Sometimes when you’re writing code, you want to verify an assumption quickly, check how your API works, or simply prototype and execute a small part of your code.
What common options are available to us?
- Create a separate small project, put the code to verify into its
Main()method, and add all the necessary dependencies.
- Hook the code to verify to a random button and start the debugger (and hopefully remember to remove the code afterwards).
- Write a temporary unit test and execute it with the Unit Test Runner.
Well, with ReSharper 9.2’s new run configurations there’s now a better way.
With the caret on a static method without parameters, press Alt+Enter to see a context action called Debug:
Calling this action triggers debugging, with this very static method used as an entry point. In other words, without breaking your coding flow, you can write a
public static void SomeTestMethod() right where you’re coding and quickly launch the debugger.
Under the hood, this context action is based on a new feature, run configurations. The feature grabs information required to execute from the current project, creates an implicit run configuration, and actually executes it.
The Debug menu item can be expanded to reveal the entire set of available actions: Debug, Run and Profile (available if dotTrace is installed), each in two varieties: with or without building. Each of the expanded actions opens a dialog box where you can refine configuration parameters as necessary, and execute the configuration with or without saving it for the future.
When you choose to save and execute, your settings are persisted so that you can reuse them later. There are three ways to access a saved configuration:
- A pinned gutter icon next to a static method
- The Run Configurations pop-up that is available by selecting ReSharper | Tools | Run Configurations or with a shortcut (Ctrl+Shift+Alt+R in both Visual Studio and IntelliJ keymaps)
- If you have dotTrace integrated into Visual Studio, you can also access run configurations via its Performance Snapshots Browser (ReSharper | Profile | Show Performance Snapshots).
- Executable: Allows running any executable file.
- Static Method: As suggested above, this lets you run any static method that doesn’t have parameters.
- Project: Allows executing a Visual Studio project (which in essence emulates setting a project as startup and launching it immediately).
- Alt+F5: Debug without building
- Ctrl+Alt+F5: Execute a configuration without debugging and building
- Edit, Duplicate and Delete: Fairly self-descriptive.
- Share/Unshare: Saves a run configuration to shared solution settings (instead of the default personal solution settings), which enables sharing the run configuration among all developers working on the current solution.
ReSharper 9.2 provides three kinds of run configurations:
You can add any of these configurations via the Add… submenu in the Run Configurations pop-up.
In addition, there is a new item in the project context menu, Create Run Configuration, which creates a new project run configuration.
The Run Configurations pop-up provides quick keyboard access to configurations. It allows you to execute any run configuration in any supported execution mode. Each configuration’s submenu provides a set of Configure commands.
One of these commands, Select, deserves a notable mention. Select assigns the current configuration to launch when you invoke Visual Studio’s own Start (F5) and Start Without Debugging (Ctrl+F5) commands. In addition, two Alt-modified shortcuts are added which affect whether or not a solution is built before launch:
A setting called Don’t build by default that concludes the Run Configurations pop-up serves to swap the default and Alt-modified actions. For example, it makes F5 invoke debugging without building.
Other Configure options include:
Subscribe to Blog updates
Creating Custom AI Prompts
AI has swept through the software development industry like a wildfire. So people want to learn how to best use AI in their day to day tasks. In this post we’ll take a look at how to write custom prompts for use with the JetBrains AI Assistant in ReSharper and Rider so you can make the most of AI.&n…
12 Debugging Techniques In JetBrains Rider You Should Know About
Twelve must know debugging features in JetBrains Rider every developer should know.
Interceptors – Using C# 12 in Rider and ReSharper
Welcome to our series, where we take a closer look at the C# 12 language features and how ReSharper and Rider make it easy for you to adopt them in your codebase. If you haven’t yet, download the latest .NET 8 SDK and update your project files! In this series, we are looking at: Primary …