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: