Archive for the ‘ReSharper Tips&Tricks’ Category

Importing / Exporting Templates and Patterns in ReSharper 6.1

Monday, January 23rd, 2012

 

One of the changes introduced with the new settings in ReSharper 6.1 is how importing and exporting of templates and custom patterns are done (Custom Patterns were previously known as Structural Search and Replace).  As part of the unification of settings, Templates and Patterns now fall under the same modus-operandi when it comes to importing and exporting as other settings do. This is very similar to how our IDEA based IDE’s such as IntelliJ, WebStorm et al. work. However, certain legacy functionality is also available depending on what needs to be done.

The de-facto choice

Be it Templates or Patterns, when you want to import or export them, the recommended approach is to use the Manage Options dialog

 

SNAGHTMLa44bc04

 

To export, we merely select Export to File. ReSharper prompts us with a dialog box of what we would like to export:

 

SNAGHTMLa471579

 

At this point we can select whether we want Live Templates, Patterns (StructuralSearch*) or both. It is important to note that if you do not have any user defined templates and/or patterns, then these options are not available, i.e., you would not see the LiveTemplates / StructuralSearch checkboxes.

 

The exported file format is only compatible with ReSharper 6.1 and higher (.DotSettings file).

 

Importing

When it comes to importing templates and patterns, if these are in .DotSettings format, then it is merely about adding another layer. We select the file to import, and are prompted on what settings we’d like imported:

 

SNAGHTMLa62f7ad

 

The benefit of this approach is not only that it keeps all settings centralized, but it also allows us to mount and un-mount related templates.

 

* StructuralSearch comes from the old name giving to Custom Patterns which was Structural Search and Replace

 

Exporting Individual Templates

One option that is currently not available using the Manage Options dialog when dealing with the export of templates is to selectively choose which ones we’d like exported. If we want to only export specific templates, we need to use the Template Explorer (previously named Live Templates)

SNAGHTMLa66c44e

 

We can then select individual templates and choose the Export button. This is basically the old behavior prior to ReSharper 6.1. The difference however is that the file exported is in the new .DotSettings format. In this regard, there is no difference between this approach and the previous Manage Options one.

 

Dealing with legacy templates and patterns formats

The Templates Explorer window also has an option to import Templates

 

image

 

Although this allows the newer DotSettings file format, we usually should only use this when trying to import legacy templates (from version 6.0 and lower).

 

When it comes to Patterns, when trying to import older ones, we can use the Import from R# v6.0- button on the Custom Patterns options page

 

image

 

 

Summary

With the new settings we’ve hopefully made sharing of Patterns and Templates a little easier. There are still improvements to make but any/all feedback or changes you’d like to see are welcome. Please log them in our issue tracker so that they can be managed better.

Per Project Settings or How to have different naming styles for my test project

Wednesday, January 18th, 2012

 

One nitpick that I myself and many have had with ReSharper is not being able to have different naming styles for types based on different projects. In my code I normally name classes using CamelCase

 

image

 

and in my test project I use all_lowercase

 

image

 

Unless you add all_lowercase as a valid naming style, you’ll always end up with those squiggly lines under all your tests. And let’s admit it, it’s not a big deal but it’s annoying. #FirstWorldProblem

 

Say hello to my little layer

With ReSharper 6.1 we introduced the concepts of layers, which open up many new possibilities, including sharing settings on DropBox and or setting company wide standards. What you might not know is that it allows Per Project Settings too! No big deal if you didn’t know, since we currently do not support it via the User Interface so it would be hard to figure it out. However it’s pretty simple to do and I’m going to show you how.

 

Our goal here is to allow all_lowercase settings for classes in our test project (Tests) and not permit the same in other projects (Project). This is the sample project layout we’re going to be working with

 

image

To make this happen, we need to create specific settings for the Tests project and allow the possibility of classes being all_lowercase. That is, the Tests project needs its own DotSettings file.

 

Since there’s no specific button or option to add Per Project settings in the UI, this is where we need to kind of use a workaround. We need to have a Settings file for the project and then edit the options and save it to this file. There are many ways to create this new settings files. We can copy the solution one and rename it, we can export the current settings, we can mount a new layer and have ReSharper create it for us, etc.

We’re going to use this last method. Why? Because since ReSharper mounts it when it creates the file, it will allow us to edit the settings too.

 

 

1. With the Solution open, click on Manage Options under ReSharper

 

2. Under This Computer, click on the Add Layer icon (on the right) and select Create Settings File

image

 

 

3. Save the file to the Tests project folder, in our case that would be under SolutionDir\Tests and name it (and here’s the important part) Tests.csproj.DotSettings. That is, it should be named with the ProjectName, followed by csproj or vbproj based on the type of project and with the extension DotSettings.

 

4. Now that we have the settings file mounted, we need to change the required settings, which in our case is to allow classes to have all_lowercase (this obviously works for other settings too). As such, double-click the recently mounted file or right click and click on Edit

 

image

 

5. The Options dialog comes up. We want to edit the naming styles

 

image

 

Modify any other settings you wish at this point and once done, hit Save on the Options dialog.

 

image

 

At this point, we can remove the mounted settings as its not required for it to actually work. We can also leave it in order to easily access the settings for the project in the future. If you do leave it, make sure you uncheck the checkbox so that settings are not applied to the entire solution.

 

[Recommendation: If you decide to leave the settings mounted, mount these under Solution Shared or Solution Personal as opposed to This Computer so that you don’t end up with a long list of different settings files]

 

 

As soon as we hit Save, the new settings automatically are picked up by ReSharper and take effect. We can now see that the naming style no longer appears incorrect under the Tests project

 

image

 

and if we try and use the same style in the actual Project we do get the warning

 

image

 

The UI will come

Once you do this once, you can pretty much copy the same file over to your different projects and rename it to match the project name. In one of the next versions of ReSharper we will provide a more intuitive UI (or should we say we’ll provide an actual UI) for this. For now however, I think this minor hack will make a few people happy!

ReSharper 6.1 Settings: DropBox and Company-wide

Tuesday, December 6th, 2011

This post is about ReSharper 6.1. For other features in ReSharper 6 (both 6.0 and 6.1), please see previous posts introducing ReSharper 6:

EAP Warning: This post is based on ReSharper 6.1 Early Access Program and some things such as screenshots and minor details might vary from the time this has been written to the time of release.

In a previous post on ReSharper 6.1 Settings, we introduced the concept of layers and covered a few scenarios when it comes to sharing of settings across solutions. In this post we’re going to cover a few more, namely: syncing settings over DropBox and providing a global setting for all projects across a company.

Syncing with DropBox

As developers we often end up working on multiple machines, whether it is that we own a desktop and laptop, or two desktops, one at work and one at home, or any other combination of scenarios, we have the need to alternate between machines. With the new layers settings in ReSharper 6.1, sharing the same settings in these cases has now become quite easy.

The idea is simple: add a new Global Layer and host the file in a DropBox folder (I’m using DropBox, but obviously you can use any other mechanism that syncs files remotely). In order to do this, we first need to export the current settings to that new file and then mount it.

1. Click ReSharper | Manage Options…

image

2. Select the Global Settings and click on Export to File. It will prompt for a filename. The idea is to place this file in a Dropbox folder. Select everything from the following screen except Housekeeping

image

It is important to note that only items that currently have non-default values will be displayed in this window. For instance, under PattersnAndTemplates, we’d see an entry of StructuredSearch if we were to have some custom patterns in the current context, as shown below

image

3. Select Add Layer | Existing File and select the file created in the previous step.

image

[Note: This screen will most likely be updated in a future release to combine the “ReSharper Global Settings” under the group header as this is a default layer that cannot be removed and therefore cannot intervene in normal operation such as priority]

We now have to repeat step 3 for each of our machines. Once we do that, the settings will automatically be loaded every time DropBox syncs.

Providing Company-Wide Settings

It should be pretty apparent that providing company-wide settings across all projects is pretty much the same as sharing via DropBox. We just need to provide a file. If we want to provide solution company-wide settings, we’d add the layer to the solution group. This would allow an alternative way of sharing settings which wouldn’t require the file to be checked in to source control.

Other operations to perform with Settings

Settings can be imported, exported, activated and deactivated (marking the checkbox or unchecking) at any point. We can also Copy To button to copy settings from one layer to another layer, making it also easy for sharing. In essence you can do pretty much anything you like now.

Why so many layers?

You might be thinking, if I could setup my settings to read from a specific file, why would I want more layers or the ability to order them in priority?. The idea with layers is that each one can add one or more configuration settings. This means that for instance a company could have a layer where only code formatting settings are defined, another layer where templates are defined and so on and so forth. When we export settings to a file as shown in two, we define which settings we want exported. We do not have to select them all like we did previously. We could for instance only choose to export Templates, and mount a layer where only these are defined. ReSharper can understand that there are different options in different layers and provides us access to them all. We don’t have to worry about this. The only thing we might need to take into account is if one layer overrides another one’s settings. That’s where the Move Up / Move Down comes in, allowing us to specify the priority.

Summary

The layers provide a lot of flexibility when it comes to sharing settings, either between two machines, a team or company-wide. Use them, abuse them. Give us your feedback.

ReSharper 6.1 EAP for Visual Studio 11

Thursday, November 10th, 2011

We recently announced the availability of ReSharper 6.1 EAP which includes initial experimental support for VS11. What wasn’t included was an installer, which made the whole support pretty much useless. We only realized this after shipping it and someone tweeting “WTF is VS11 checkbox?”

FAIL!

In all seriousness though, we knew that this was missing. We had intended to provide a VSIX that allows you to install ReSharper 6.1 in VS11 on the same day of the release of EAP, but it didn’t happen. However, that VSIX is now available, and you can obtain it from the nightly build (which btw have resumed) page, as well as the SDK. The evaluation license key for the VSIX is also provided. To install it into VS11, merely close down the IDE, double-click on the VSIX and you’re done.

If you have any issues please report them here or on our forums.

MSpec Runnner Available for ReSharper 6.1 EAP

Thursday, November 10th, 2011

Below is a link to the MSpec binaries compatible with ReSharper 6.1 EAP. This is just a temporary link until MSpec is officially updated by Alex who’s currently chasing Elephants in Uganda!

Download the binaries from here

Please give us feedback here if you have issues.

Thanks.

The JetBrains Magical Mouseless Continuous England User Group Tour

Tuesday, October 18th, 2011

After months of preparations and in collaboration with  NxtGen User Groups, VBug and Anteo, we are happy to announce the upcoming JetBrains User group Tour of England: 5 Days, 5 Cities, finishing it off in London in style!

The Tour Dates

  • Monday 14th Nov - Essex
  • Tuesday 15th Nov - Cambridge
  • Wednesday 16th Nov - Manchester
  • Thursday 17th Nov - Coventry
  • Friday 18th Nov - London

(For more information and Registration, see below)

The Agenda for Essex, Cambridge, Manchester and Coventry

Mouseless Driven Development

Do you know ReSharper, are using it or have used it in the past? Do you think you are getting the full potential out of it? Even developers that have been using it for several years often only scratch the surface. Come and learn all the tips and tricks of ReSharper and see how to use it to it’s full potential to truly create a mouse less driven development environment.

The Agenda for London

The London event will be slightly longer, but will be compensated with Food and Beer!

Mouseless Driven Development

Do you know ReSharper, are using it or have used it in the past? Do you think you are getting the full potential out of it? Even developers that have been using it for several years often only scratch the surface. Come and learn all the tips and tricks of ReSharper and see how to use it to it’s full potential to truly create a mouse less driven development environment.

Continous Delivery

Paul Stack joins us to talk about Continuous Delivery and how to use TeamCity for this purpose:

Continuous Delivery is all about allow features to be delivered in a more timely and reliable fashion. In this session, Paul will introduce the concepts of continuous delivery, through continuous integration;  automation of builds, test and deployment process, version control techniques for Continuous Delivery, Pitfalls, Objections and Obstacles.

Sebastian Lambla will show us to to twist Visual Studio and ReSharper to provide dynamic plug-in functionality with OpenWrap.

Registration

If you are going to attend the London meeting, please use our EventBrite page to sign up. If you are going to attend one of the other meetings across England, please use the corresponding link below to register directly with the user group.

(In London we will be providing Food and Drinks, so please make sure that you sign up ahead of time. Places unfortunately are limited to approximately 70 people!)

Scotland

Unfortunately, despite our initial intentions of also including Scotland in the tour, we were not able to due to scheduling. However, we hopefully do plan to repeat the tour with Scottish User Groups in the New Year so please stay tuned!

Thank you!

A big Thank You to the Coordinators of NxtGen User Group, VBug and Anteo for their efforts in organizing this tour and collaborating with us in all possible ways.

Industrial Logic: Your Personal Trainer 24×7

Monday, September 12th, 2011

Test Driven Development is easy. You write a test, then you write the code. Seems simple enough, yet it normally is not, and when you’re just getting started, you often make mistakes. It doesn’t matter how many times you read the steps or follow a course, as a novice you are still unsure whether you’re doing it right or wrong.

It would be great if somehow, there was someone constantly monitoring you and telling you whether you’re taking the right steps. Whether you are refactoring when you should, whether you are making tests fail before they pass. It would not only help newbies, but also help some of us to be a bit more disciplined. Up to now, this kind of monitoring was really only viable while having an instructor next to you. However, that has changed.

Industrial Logic, founded by Joshua Kerievsky, author of the well-known book on Refactoring to Patterns (highly recommended) have courseware on topics such as design, code smells, refactoring and test driven development. The difference with these courses however is that apart from being interactive and providing exercises, they also monitor how you perform these exercises by using a neat little plug-in for ReSharper that they’ve developed.

How it works

When you sign up for a course that involves exercises, such as their TDD course, you are prompted to install a ReSharper Recording plug-in:

image

Once this plug-in is installed, it will then automatically start recording any exercises you do. In the case of the TDD course, these exercises are designed to show you the flow of TDD: Red, Green, Refactor. It gives you a brief description of the required code to write and starts you off with a blank test. The one below for instance is to calculate bonuses:

image

Once you complete the exercise, you then upload a file. This file is the recording that the ReSharper plug-in has made. It includes information such as compiler errors, warning, the refactoring steps you’ve made, and a whole bunch of other useful information. Once this file is uploaded, it is analyzed and results are produced for you:

image

This graph indicates the portion of time that your code had errors, the amount of time with failing and passing tests as well as the actual phases. Every dot on the graph also provides detailed information about the event, along with a score.

These scores are determined by the activities that take place:

image

For instance, here we see that we performed a refactoring while having compilation issues, giving us a score of 0, or performing another refactoring before tests are run, resulting in a –1. These events all add up along with other factors to give you an overall score:

image

It doesn’t end there

The great thing about this however is that it doesn’t end with your score. As I mentioned, this course is fully interactive, which means that not only can you interact with instructors, but also other alumni, via in-place forums. For instance, below is a screenshot of a question that is asked after the exercise. It includes not only your response, but the percentage of the overall responses from other students along with open discussions from instructors and alumni:

image

This kind of interaction is invaluable. Not only do you have a monitor recording your steps, but you can also discuss issues you encounter or doubts you have throughout the course. What is also great is that all the mentors and instructors of Industrial Logic make it clear that there is no absolute truth. Every response, every comment, is always with the utmost respect and given from a personal experience perspective.

Watch it in action

The folks at Industrial Logic have put together a small video which shows how this works in action:

Beyond Exercises

This recorder is great for exercises and learning, but it doesn’t stop there. When signing up to their courseware, you are also provided the option to have the ability to record steps on live projects and have them analyzed (Sessions album). Think of the scenarios this could help with! Not only can you see for yourself if you are doing things in ways that can be improved, but it also allows you to teach and help junior developers on your team.

The TDD course as well as many of the other courses surrounding refactoring and code smells by Industrial Logic are of the highest quality. They have an extensive album (as they call it) of courses.

Special ReSharper 6.0 Recorder Launch offer

To celebrate the release of Industrial Logic’s Recorder for Resharper 6.0, they are offering a 30% discount on the purchase of one of the following albums:

To obtain this special offer, please use the following discount code when ordering your album: ILRECORDER60.  Please note that this code is valid until the 30th of September, 2011.

New Features in ReSharper 6 Unit Test Runner

Tuesday, August 23rd, 2011

Previous posts introducing ReSharper 6:

ReSharper 6 includes a series of new features and improvements in the test runner, as outlined below.

NUnit TestCase

We now fully support NUnit’s TestCase, TestCaseSource, Values, Ranges and other attributes. Given the following tests:

image

ReSharper outputs the results as individual tests, appropriately grouped.

image

This allows us to now run and view tests individually.

image

As expected, dotCover and dotTrace also provide support for this.

Support for Coded UI Tests with MSTest

Coded UI tests (when appropriate) are also supported now with the ReSharper test runner

image

Default Keyboard Bindings and Test Re-Runs

Out of the box ReSharper now ships with pre-defined shortcut keys for running, debugging, re-running tests, among other things. This eases the pain of having to map keys on new installations (as of ReSharper 6, you no longer loose your key bindings during upgrades!). By default, the key-bindings for the schemes are:

Operation Visual Studio IntelliJ IDEA
Run Unit Tests. Context Sensitive Ctrl+U, R Ctrl+T, R
Debug Unit Tests. Context Sensitive Ctrl+U, D Ctrl+T, D
Run ALL Unit Tests Ctrl+U, L Ctrl+T, L
Run Current Session Ctrl+U, Y Ctrl+T, Y
Rerun last test. Context Insensitiveimage Ctrl+U, U Ctrl+T, T

This last shortcut is a new feature added in 6 which allows us to re-run the last test we just ran. And we can run it from anywhere! This makes TDD for instance very easy as we can write some code, be in the actual code and run the test, without having to switch back to the test or open up the unit text explorer.

Running Tests from File Structure and Find Results Windows

You can now run Tests directly from the File Structure Window

SNAGHTML14c0e0a

as well as the Find Results Window

SNAGHTML14d0b1d

again, removing some of the friction when it comes to testing.

Categories

Certain Unit Testing frameworks provide test categories. For example, in NUnit there is the [Category] attribute. ReSharper now allows us to ignore specific categories and not run them during a test run. This is accomplished by indicating the category under ReSharper | Options | Unit Testing

image

When running unit tests, these appear as ignored.

image

This is useful for instance when we want to avoid running certain tests during development sessions.

Categories can also be used to run a specific group of tests by selecting these from the context menus:

image

Other improvements

Some other minor improvement or previous features we have blogged about include:

  • QUnit Support
  • Unit testing Sessions are now persisted between Visual Studio restarts
  • Ability to run tests in parallel from different assemblies, decreasing testing time (can be turned off in ReSharper | Options | Unit Testing)
  • General performance improvements
  • Update Progress indicator on Windows task bar

image

As always, we welcome your feedback

Australia: First Contact

Monday, August 22nd, 2011

image

We have a lot of users in Australia, yet we’ve never managed to get out over there for a conference. That’s about to change. Next week, myself and Sergey Coox (ReSharper Project Manager) will be heading to the Gold Coast for TechEd Australia. We are sponsoring the event as well as having a booth present. It is going to be a great opportunity to see and talk first-hand to our users and also a personal chance to get to see (albeit very little) of Australia. We will ship a few hundred “I see dead code” T-Shirts also, so make sure to stop by the booth to pick yours up.

ReSharper Tips and Tricks Demo

We’ve managed to secure one whole hour at the Create Demo Booth that will be in the exhibit area to hold a ReSharper Tips and Tricks session, similar to those that have taken place at other conferences. This will take place on Thursday 1st of September 1 pm - 2 pm. It will be somewhere in the Exhibitor area. Pass by the booth during the week for more details.

File Header Macros in ReSharper 6

Monday, July 25th, 2011

Previous posts introducing ReSharper 6:


Sometime ago I wrote about Automating File Header Information, showing how to insert license information and other data in project files. One of the shortcomings ReSharper had however was the inability to support macros. Something as simple as inserting the current year or filename required the support of StyleCop for ReSharper. ReSharper 6 now support macros allowing file headers to contain varying information:

SNAGHTML13afe47c

For instance, in the previous license header, the Copyright years are fixed to 2010 – 2011. It also has no information relevant to the actual project. We could of course hardcode the name of the project in there but since this setting is not solution-specific, it would be of little use. Other data such a filenames however would be impossible to do.

With ReSharper 6 we simply remove the hardcoded values and replace them with macros. We can either type them in or click on the corresponding macro, which will insert it at current cursor position:

image

With this change in place, next time we run a code-cleanup and have the Update File Header option activated, we will get up to date and project/file specific header information inserted. Next feature request: Custom Macros!