Archive for the ‘ReSharper Tips&Tricks’ Category

Meet dotTrace 5.3.2 Performance with CLR 4.5 support

Tuesday, May 14th, 2013

Today we are happy to announce availability of a new maintenance release of our .NET performance profiler. Please feel free to download and try the latest dotTrace 5.3.2 Performance.

Starting from this update dotTrace Performance supports the latest version of CLR. In case you have already updated CLR to version 4.5 or just plan to do it, we would recommend to use this version of the profiler.

ReSharper 8 EAP: NuGet based Extension Manager

Friday, May 10th, 2013

ReSharper has always had a powerful extensibility story – its Open API allows plugins to use the same APIs that the core product uses. But distribution – discovery, installing and uninstalling – has previously been left to the plugin author, meaning the user is left with an experience ranging from msi installers to zip and batch files. Recently, .NET has seen the success of the NuGet package manager, which makes it very easy to install, uninstall and update libraries in a project. We’d like to bring that ease of use and discovery to ReSharper, which is why we’re very happy to be taking the wraps off our NuGet based Extension Manager.

ReSharper Extension Manager window

The latest EAP build of ReSharper 8 adds support for extensions to be distributed as NuGet packages. You get to use a very familiar interface to browse and install extension packages from our new extensions gallery. Of course, you can easily uninstall and update, too, and ReSharper will check for updates for you, and notify you when a new build is available – perfect for keeping up to date with EAP changes.

ReSharper update notification balloon tooltip

Speaking of EAP changes – since ReSharper 8 is currently still under development, it is obviously changing and evolving with each EAP release. Which means our packages are marked as “prerelease”. Once 8.0 is released, these will of course become Stable. Until then, please make sure to select “Include Prerelease” when browsing with the Extension Manager, or in the Gallery.

Extensions, Not Plugins

A very important change, though, is that an extension is not just for plugins. An extension can also be used to distribute ReSharper’s settings files and External Annotations, meaning you can now write useful extensions without even having to write any code.

The benefit of distributing .dotSettings files is that these are the files used by ReSharper to store Live Templates, Structural Search and Replace patterns, and other settings. For example, the xUnit.net test runner extension includes a plugin to provide the test runner capabilities, but also includes a .dotSettings file, adding lots of Live Templates to help generate code to write asserts faster.

Live Templates imported by the xUnit.net extension

And the sample patterns catalog extension adds a sample set of Structural Search and Replace patterns. These patterns are a very powerful, declarative way of analysing code and applying the standard warning squiggly underline highlight. What’s more, they can also provide a declarative means for creating a quick-fix for this code – adding an action to the alt+enter quick-fix menu to replace the code. See here for an introduction to SSR, and check out these posts for more information.

Structural Search and Replace dialog with sample patterns imported

Of course, settings files aren’t limited to Live Templates and SSR patterns. While these were the primary motivation for adding support for .dotSettings files, it opens the door for more interesting extensions – defining code formatting standards, code cleanup profiles, extra To-do items, or even a different set of opinionated code inspection defaults (don’t like our default “var” recommendations? Change them!).

Extension packages take advantage of ReSharper’s settings layers. If the extension contains a .dotSettings file, it is added as a read-only layer. The settings in the file are merged with the other layers in your installation (This Computer, Solution and project files – see this post for more information on layers), and naturally appear in the Options dialog or Live Templates Explorer. This means you can edit the templates, patterns or other settings, and any changes are then saved in the This Computer layer.

If you don’t want these extra settings (for example, you want the test runner, but not the included Live Templates) you can easily remove them from the system by disabling the layer in the Manage Options dialog. The settings, templates or patterns are immediately removed.

ReSharper's Manage Options dialog showing xunitcontrib settings layer deselected

External Annotations are xml files that contain a map between ReSharper’s annotation attributes, and pre-compiled assemblies. ReSharper’s code analysis uses these annotations to make better decisions about the warnings to show. For example, without annotations, this test code warns about potential null usage, even though the preceding Assert will throw an exception if the value is null – in other words, the value is guaranteed to be not-null when accessed.

ReSharper warns of potential null reference exception, even though the line will never be hit due to preceding Not Null assert

The xUnit.net extension adds annotations for the xunit.dll assembly, which tells ReSharper that Assert.Null will throw if the passed parameter is null. Now, ReSharper knows that the second assert will never get hit, and marks it as unreachable.

ReSharper highlights unreachable code due to preceding assert

ReSharper ships with annotations for the BCL, and some annotations for third party assemblies, notably to enable INotifyPropertyChanged support. Extensions can now distribute annotations for other third party assemblies.

Dependencies

Since extensions are NuGet packages, they can have dependencies. Someone could write an extension that exports a Live Template for creating test methods. That template could use a macro from another extension to make sure the method name you type gets converted to a valid name – changing spaces to underscores, for example.

Bundled Extensions

Another exciting benefit we get from the extension manager is the ability to have bundled, or pre-installed, extensions. These are simply extensions that are installed for you as part of the normal installation process. Once installed, they behave just like normal extensions, and we can push updates to the Gallery at any time, allowing us to update these plugins on a separate schedule to ReSharper itself.

In the latest EAP build, we’re bundling our NuGet plugin which uses NuGet to add package references, rather than file references when importing types. We now get the best of both worlds – this really useful functionality is included by default for every ReSharper user, and we have the flexibility to update it at any time, decoupled from ReSharper’s release schedule.

Custom sources

Of course, since this is based on NuGet, we get to take advantage of the existing infrastructure and tooling available in the NuGet community. Our Gallery is based on the NuGet Gallery sources, and is the default, primary location for getting extensions (remember to select “Include Prerelease”!). But you can also use the Extension Manager page in the Options dialog to specify extra sources – local or remote file system or a custom NuGet feed, such as TeamCity or MyGet. This makes it easy to install private, company wide extensions that target your specific needs, or nightly builds of an extension you build, or perhaps create a curated feed of your favourites.

custom_sources

How to Build Your Own Extensions

Building extensions is very straightforward. While we’re based on NuGet, we have a very different purpose to NuGet – extensibility information as opposed to assembly references. So we don’t use the standard libs, tools or content folders. Instead, we have our own folder structure that makes more sense for the data we need to distribute in the package. But that’s really the only difference. We still use the .nuspec file for metadata, and we pack and push the .nupkg file to the ReSharper Gallery in the same way – sign up for an account, get an API key and push away! You can get more information on creating an extension package at the ReSharper 8 devguide site, and if you have more questions, please email us at resharper-plugins@jetbrains.com, or send a message to the new resharper-plugins Google Group.

Please note that the Extension Manager relies on NuGet’s core library to implement a lot of its functionality. Since this is a .NET 4 library, the Extension Manager is limited to Visual Studio 2010 and 2012. We’re looking at ways to improve this as we progress through the EAP.

We hope you enjoy the changes we’ve introduced around extensions. Please try it out and let us know your feedback. We’re still quite early on in the EAP cycle, so expect changes – but if there’s something you want to see changed or updated, let us know! You can report issues at our YouTrack instance.

And remember, you don’t need to write a plugin to release an extension – let’s see some Live Templates and SSR patterns!

New Features in the Latest ReSharper 8 EAP

Tuesday, April 30th, 2013

Good news everyone — we’ve got another EAP build ready and it should come as no surprise that we’ve got a few new features to talk about. So without further ado, here’s what we’ve got in store for you today.

Extension Manager or how to provide xUnit.net support

We sometimes get requests to provide certain features out of the box, functionality that is currently provided via plugins. xUnit.net support is one of these.

While doing this certainly has its benefits, it also has disadvantages. As such, we decided instead to take the opportunity to address the core problem, which is to simplify the discovery, installation and updating of ReSharper plugins.

We’re very pleased to introduce our NuGet based Extension Manager. It’s now very easy to add extensions and plugins to ReSharper, all from a user interface you’re very familiar with from NuGet. Simply open the Extension Manager from the ReSharper menu, and you’ll be able to browse and search for extensions from the “Online” category - make sure you select “Include Prerelease” in the drop down first - these are still EAP packages!

So to get xUnit.net test support, simply find the xunitcontrib package and hit Install.

That’s all there is to it! ReSharper now has support for running xUnit.net tests, and includes Live Templates and External Annotations to make your test code writing experience better.

We’ll be taking a more in-depth look at this feature very soon, but one important point to make right now is that because NuGet is a .NET4 library, the Extension Manager is only available in Visual Studio 2012 and 2010.

ToString() Format Completion

ReSharper already has a few features related to String.Format() usage, such as for example inspections and fixes related to format arguments being used in the format string. However, in this EAP we’re taking it a bit further by adding code completion for types which have well-known format specifiers (such as DateTime, TimeSpan, Guid, enumerations and many others):

Multi-File Templates

By popular demand, ReSharper’s support for file templates has been expanded to incorporate the possibility of creating several files from a single template. You start, as always, by creating a single file template. But then, ReSharper gives you controls to add additional files: you can either add a new file or a file from an existing template:

Choosing one of these options adds another editor into the template editor window. In this editor, you can specify the placement of the file (either a relative location or an ASP.NET code-behind file), the name of the folder to place the file into, and of course the name of the file. Then, just edit this template as you would any other — you can reuse the parameters you declared for the first template.

You can add as many files as you want and once you come to fire the template, all the necessary files (and folders, if they do not exist) will be automatically created in the right places.

Go To Generic Subsitutions

When you have the usage of a generic type such as List<Foo>, it’s easy enough to find all usages of List<T>, but what if you want to know the exact types that List<T> is being specialized with. To help with this, one of the new navigation options is to look for Generic Substitutions:

Once you fire up this navigation item, ReSharper will search for all the types that are used to substitute the generic parameter T and will show you a summary tree grouped by the type used to substitute the generic parameter. You can drill down into the tree to find out the exact locations where a particular type is used:

Blue Theme Support

Visual Studio 2012 Update 2 has been released with support for a Blue Theme, and we’ve made adjustments to ensure that ReSharper plays nice with it too:

We’ve got a lot more in store, and we’ll be blogging in the coming weeks about new features as well as giving in-depth overviews of the ones we’ve already mentioned. Meanwhile, please feel free to check out the EAP and let us know what you think!

Refactoring Legacy Code Bases, Free Online Event May 8

Wednesday, April 17th, 2013

In cooperation with Microsoft, join JetBrains’ Hadi Hariri for the free online event, Refactoring Legacy Code Bases using Microsoft Visual Studio and ReSharper. The session is intended for architects, designers and professional developers.

Refactoring Legacy Code Bases
Wednesday, May 8, 9:00 AM - 10:00 AM Pacific Time (GMT-08:00)

Not everyone has the possibility of working on Greenfield projects or doing TDD or BDD. Many of us often end up having to work with legacy code bases that have little notion of what SOLID design principles are and unit tests are non-existent. It can be daunting to have to maintain these types of systems. However, with a little bit of effort, we can try and make the best of the situation. We can combine some well-known refactoring techniques, along with code analysis and design concepts to improve the quality of the code.

Registration is required to attend. We hope to see you there!

ReSharper’s Web Path Mapping Explained

Monday, April 15th, 2013

One of the many scenarios that ReSharper seeks to address in web projects is a situation where the locations of files during the design of the app are different from the locations where the app gets deployed. This makes life difficult for ReSharper, since it doesn’t know where to go looking for the relevant files. Luckily, the Path Mapping feature lets you configure the locations of those paths.

There are two mechanisms that can both be used to configure path mappings – context actions and explicitly opening the Path Mapping dialog.

When ReSharper sees a path that it doesn’t recognize, it will underline the path with a wavy line, complaining that it doesn’t know where the path is. At this point, pressing Alt+Enter will show you several options for how the situation can be handled:

The first option, Ignore path, simply tells ReSharper to not bother inspecting this particular path wherever it may appear. This is useful in situations where, for example, you are referencing a file that doesn’t yet exist, and might be created later.

The second option is to Set path mapping, i.e. define explicitly how the path is handled.

Once again, there are two options: Substitute replaces a path with a different path, whereas Ignore chooses to ignore the path and is functionally equivalent to the Ignore path context action.

The Path mapping dialog box doesn’t only show up when you use a context action: you can also open it up by selecting the Path mapping element of the properties of the web project you’re working with. Note that we’re talking about the property grid (F4) rather than the tabbed property pages. To bring up the dialog, just press the button next to Path mapping.

Incidentally, the text value next to the button can be one of two possible options – either Custom indicating that some mappings have already been created, or Not set when none have yet been defined. At any rate, just as with the context action, pressing the button brings up the Path mapping window where you can create, delete and change mappings:

We hope you find this feature of ReSharper useful and your experience of developing web applications becomes a little more enjoyable. Develop with pleasure!

Webinar Recording: Jon Skeet Inspects ReSharper

Thursday, April 11th, 2013

On Tuesday, April 9th, we held a free webinar with Hadi Hariri and C# legend Jon Skeet. The concept was simple enough: to play with some of the most sophisticated ReSharper code inspections and have Jon try to break ReSharper with tricky code samples.

The recording of this webinar is embedded below and can be found directly on YouTube and JetBrains.tv. The examples used are also available for download.

We would like to thank all of the webinar attendees for your participation, questions and tremendous turnout and of course to Jon, thank you for taking your time to join us and share your wealth of knowledge!

About This Webinar:

Jon Skeet, man, father, legend. Some call him the Chuck Norris of C#. The guy that the compiler bends to obey joins us for this webinar to walk us through some of the inspections that ReSharper offers. He explains the theory behind it, tells us whether he agrees with it or not and does his best to try and break ReSharper. You can follow Jon on Twitter @jonskeet.

 

 

ReSharper 8 EAP, Build 3: What’s New!

Monday, April 8th, 2013

You have probably already guessed that this post is about a new set of features that has appeared in the new build of the ReSharper EAP late last week, so, without further ado, here’s what we’ve got in store for you:

Bulb Menus in Margin

In an attempt to streamline the programmer’s interaction with gutter marks and bulb pop-ups, we have added an option to merge both of these constructs into a single construct that we call an action indicator. Here’s what it looks like:

As you can see, both the gutter mark options from unit tests and the context action on that element have been merged into a single menu. The use of action indicators is an optional feature that can be found in ReSharper’s Options under Environment|Editor|Editor Appearance:

Option #2 in the above list revers to the R#7.1-style mechanism of showing a bulb pop-up. The last option prevents any visual queues that a bulb item is available (save for the indicator itself), and only shows the menu when you explicitly open it with Alt+Enter.

Please note that this feature is available only for Visual Studio 2010 and later.

Decompiler Improvements

We’ve already talked a bit about decompilation (both in ReSharper and dotPeek), but this deserves a mention: we now know how to correctly decompile

  • async methods and await expressions, including async lambdas.

  • Expression trees — the decompiler will now help you when exporting Linq to SQL or Entity Framework code in query expressions. This means in ReSharper 7 you could only decompile an expression into this:

    whereas with ReSharper 8 you can decompile it into this:

  • Field-like events, taking into account the lock-free nature of C# 4’s add/remove accessors.

Fix in Scope

In-place fixes are great, but what’s even better is when you can apply that fix in a given scope. Take those pesky unused references, for example – now you can get rid of them not only in a file, but also on a project/solution level. All with a single quick-fix:

Now quite a few fixes can be applied to a larger scope than just the code under the cursor — including making a field read-only or removing a redundant cast.

Default Alignment Setting Adjustments

One common complaint about ReSharper’s default settings was that certain constructs we indented, shall we say, aggressively. The two particular cases of note are anonymous lambdas

And another case is indentation when a function call including parameters gets too big and is indented similar to

These and similar cases will now be treated more gently by ReSharper’s default settings.

Code Inspection Performance Improvements

Last, but certainly not least, after another round of performance improvements we’ve managed to once again speed up ReSharper’s code analysis. Specifically, the Find Code Issues command enjoys an over 2× performance improvement.

Now, you know what to do – grab the EAP and check out those features today!

Another ReSharper 8 EAP Build. More Features

Wednesday, March 27th, 2013

Earlier this month we announced the first EAP of ReSharper 8 and a set of features that came with it. Now we have another EAP build out there, and a few more features available for you to try out. Here’s an overview.

Pull Parameter Refactoring

In previous versions of ReSharper, when you invoked the Change Signature refactoring to add a parameter to a method, ReSharper offered to simply insert default values into the method. Not anymore!

Now, after you add a parameter to a method, ReSharper asks you about the ways in which you want to handle the missing parameter in all the calls:

If you choose the Resolve with call tree option, ReSharper will show you a separate tool window which lets you ‘pull’ the parameter from all available sources:

As the above screenshot illustrates, it handles various complex scenarios (e.g., inheritance hierarchies) and offers different options depending on the situation.

We’ll dive deeper into this feature in a separate blog post.

Staged Completion

In ReSharper 8, when a type being used requires a using statement, we no longer show the blue pop-up window. Instead, we simply add the type to the completion list with a note of what namespace it comes from:

To ensure that performance during the addition of these menu items does not suffer, we implemented a staging mechanism: the ordinary completion items get added first, and then the completion items for the not-yet-imported types get added to the menu later.

Grab the new EAP build and play with it!

Jon Inspects ReSharper – Free Webinar Tuesday, April 9th

Thursday, March 21st, 2013

Jon Skeet, man, father, legend. Some call him the Chuck Norris of C#. The guy that the compiler bends to obey is going to join us for this webinar to walk us through some of the inspections that ReSharper offers. He’ll explain the theory behind it, tell us whether he agrees with it or not and will do his best to try and break ReSharper. Join us for what will definitely be a fun and educating webinar.

Jon Skeet

This free webinar will take place Tuesday, April 9th from 19:00 – 20:00 CET (Central European Time). Space is limited; please register now.

About Jon Skeet
Jon is a Java developer for Google in London, but he plays with C# (somewhat obsessively) in his free time. He loves writing and talking about C# and the second edition of “C# in Depth” was published in November 2010. Writing less formally, Jon spends a lot of time on Stack Overflow… where “a lot” is an understatement. Give him a puzzle about how C# behaves which gets him reaching for the language specification, and Jon is a happy bunny. Jon lives in Reading, England with his wife and three children.

Introducing the ReSharper 8 EAP

Wednesday, March 6th, 2013

In the world of technology, no-one can afford to stand still. As new frameworks and languages come out, ReSharper does its best to keep up. This is why we are happy to announce the opening of the ReSharper 8 Early Access Program. With the forthcoming release, we are proud to announce the following features, which will be part of ReSharper 8.

Go To Everything

In preparation for ReSharper 8, we’ve put in extra effort on streamlining certain operations. One of the areas where we felt improvement was needed was the unnecessary divergence caused by the various Go To menus. In an effort to simplify things, we have altered the main Go To Type command (Ctrl+T) so that now it navigates to either types, symbols or file names, all contained within the same listing.

By default, the menu shows a listing of recently opened files:

Searches for identifiers now yield both files, types, and file members:

Don’t worry – all the previous commands (e.g., Go To File) continue to work, and dynamically switching from one context to another is supported. The functioning of selectors is, of course, left intact, so you can write things like ClassName.MemberName to locate a particular member of a class, use combo navigation, wildcards and camel-humps. In addition, we added some new selectors – for example, typing public or private helps you narrow members down by visibility. Performance of this menu has been optimized so searches should be very quick.

Code Completion Improvements

This release comes with a substantial number of improvements in the way ReSharper offers code completion suggestions.

New Items in Automatic Code Completion

The first thing to point out is that, from now on, various aspects of smart completion and import symbol completion are now integrated into ordinary code completion, once again striving for a more streamlined experience.

For example, if you take a class and indicate that it implements INotify, you will be presented with the following menu:

The completion options will now show you all the possible ways of getting at a particular interface that begins with INotify, and using it will cause the appropriate using statement to be added to the top of the file.

In addition to the above improvements, ReSharper now offers several generative completion options, specifically offering to generate code on partial and override statements:

And finally, we’ve added some minor improvements to existing completion mechanisms. For example, the completion list for a collection member now includes the keyword new by default:

Other Code Completion Improvements

In addition, we’re introducing a new concept called Double Completion. For example, when you use ordinary completion by pressing Ctrl+Space, and you don’t get the member you’re looking for, you can press this shortcut again to try locate the element in all referenced assemblies. Double Completion also works with Smart Completion, so pressing Ctrl+Alt+Space more than once will offer you various chains of calls that will get you to the right member (possibly via extension methods).

Double Completion mechanisms are supplemented by quick-fixes, so if you use it to get at a symbol that is private, a quick-fix will quickly let you alter the visibility of a member to make it accessible.

New Code Inspections

As always, we’ve added new inspections as well as improved existing ones. Here’s a small sampling of some of them:

  • You can now disable all ReSharper warnings with a single comment — instead of defining separate inspections to suppress, you can now mark code with // ReSharper disable all and ReSharper will not complain about anything until it meets a corresponding // ReSharper restore all .

  • You can now switch between array initialization expressions and array creation expressions; ReSharper offers the appropriate inspection and context actions:

  • An ability to convert recursive calls to iterative ones:

  • If a method has an overload that supports cancellation (i.e., takes a CancellationToken), ReSharper will offer to use that overload, provided that there is a CancellationToken available in scope:

  • ReSharper also supports the idea of fallback color in CSS:

This is just a sampling of some of the inspections improvements that we’ve added. We’ll publish a blog post with more in-depth information soon.

CSS Improvements

To help developers ensure correct operation of their code, ReSharper introduces configurable support for CSS3 and earlier versions, as well as compatibility checks against popular browsers:

As a consequence of these compatibility checks, ReSharper will now provide detailed information about the availability of a feature for a particular browser:

We’re working on making ReSharper progressively smarter in recognizing CSS declarations, whatever shape they take, be it in JSON:

In string literals:

And even in anonymous type declarations:

Searching for a CSS attribute has got a lot smarter, too. For example, searching for the color Red will yield all locations in CSS, JavaScript and C# where this color is used, however it may be defined:

Finally, ReSharper now supports refactorings such as the renaming of identifiers defined in CSS:

Assembly Explorer

Those of you who know dotPeek, our free decompiler, have already seen the Assembly Explorer – a window similar to the Solution Explorer that lets you explore decompiled assemblies. The great news is that now Assembly Explorer is part of ReSharper, too:

In addition to being able to load assemblies via its user interface, ReSharper also offers an option to Locate in Assembly Explorer, which will select the item currently being decompiled in the Assembly Explorer window:

The Assembly Explorer is a very powerful tool, capable of locating assemblies in various file formats (e.g., ZIP files). It’s also very extensible, a fact appreciated by dotPeek plugin writers. Its capabilities are now open for you to extend, right within ReSharper.

BAML Decompiler

While we’re on the subject of decompilation, ReSharper now supports BAML decompilation, so if you’ve got a compiled WPF app, you can easily look at its XAML UI definitions:

Note that the generated XAML above supports typical features such as navigation, Find Usages and other features one would expect from a XAML viewer.

Odds and Ends

Just a few more things that are worth mentioning.

We have made adjustments to the formatter and Code Cleanup in order to treat preprocessing directives such as #if and #region correctly. This means that constructs such as

will now correctly survive in case you execute the formatter or Code Cleanup on the file.

In addition to ReSharper as a plug-in, we are also providing a command-line tool that can be used to analyze an existing VS solution. This happens to be the tool that TeamCity uses to present ReSharper analyses. We are currently offering it as a separate, time-limited download and will be putting up new releases together with forthcoming EAP versions.

Finally, we are working hard on bringing you TypeScript support in ReSharper! It’s still too early to announce any features for it, but rest assured that it’s high in our priorities and we’ll let you know as soon as it’s ready.

Now that you’ve seen some of the features that ReSharper 8 will have, why not give them a go? Simply download the EAP and let us know what you think!