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
Thanks, we've got you!
Eager, Lazy and Explicit Loading with Entity Framework Core
Entity Framework Core (EF Core) supports a number of ways to load related data. There’s eager loading, lazy loading, and explicit loading. Each of these approaches have their own advantages and drawbacks. In this post, let’s have a quick look at each of these ways to load data for navigational prope…
OSS Power-Ups: bUnit – Webinar Recording
The recording of our webinar, OSS Power-Ups: bUnit, with Egil Hansen and Steven Giesel, is available. This was the twelfth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webi…
Accelerating Your Testing Workflow with Unit Test Creation and Navigation
Unit tests play an important role in our daily development workflow. They help us ensure our codebase's correctness when writing new functionality or performing refactorings to improve readability and maintainability. In the process, we often create new test files that accompany the p…
Introducing Predictive Debugging: A Game-Changing Look into the Future
With the introduction of debugging tools, software developers were empowered to interactively investigate the control flow of software programs to find bugs in live environments. At JetBrains, we've always strived to improve the art of debugging. Besides the more standard things you expect from a de…