New in PostSharp 4.1: Improved Visual Studio Tooling

by Gael Fraiteur on 04 Feb 2015

As we’re now in the stabilization of PostSharp 4.1, I would like to talk in a bit more detail about a few of its features. If you haven’t done it yet, you can download the last preview of PostSharp 4.1 from our web site.

Additionally to adding support for Xamarin and improving support for Windows Phone and Windows 8, we spent a lot of effort improving our Visual Studio extension.

A few highlights are:

  • Support for Visual Studio 2015, including light bulb integration, live code diagnostics and coding guidance.
  • Conservative NuGet versioning.
  • Improvements in PostSharp Explorer.
  • Support for Universal Apps (shared projects).

Visual Studio 2015

As you probably know, Visual Studio 2015 includes a brand new compiler code-named “Roslyn”. The new compiler is used directly inside the IDE and replaces various older code parsers and code object models. This new release of Visual Studio is the one that required us the most significant redesign since Visual Studio 2005, the first version we targeted with our PostSharp tooling.

Thanks to this redesign, we can now rely on powerful and well-designed APIes to understand your code, and as a result we can provide a more useful integration with the source editor.

Light bulb

The first thing you will notice is that PostSharp now makes use of the light bulb instead of the smart tag to provide refactoring actions. The light bulb UI is neater and more consistent than the smart tag one, and it includes the ability to display a preview.

Unlike the ones that are built in Visual Studio, PostSharp light bulb actions may open a dialog box if user interaction is required. For instance, if you choose Apply threading model, you will be asked to choose from the list of available threading models:

 

Live code diagnostics

Real-time code diagnostics are useful when you are implementing an advanced pattern such as a threading model or undo/redo. We implemented live analysis of the most frequent issues. Just as with other C# errors, you will see the red squiggle and the error will appear in the Error List toolbox window.

 

Coding guidance, or Cody Clippy

We took live code diagnostics to the next level. When you are in the process of implementing a pattern, for instance Immutable, we will show you the next more relevant issue to solve related to the task you are now completing, and will display links to the most relevant documentation articles.

 

PostSharp Assistant is based on analysis of your own source code in real time, so it's much more relevant than previous guidance systems.

PostSharp Assistant is a non-modal tool window that you can dock where you want. Of course you can always disable the feature once you learned how to implement a pattern.

Conservative NuGet Versioning

In the past, it was too easy to mess your versions of PostSharp in multi-project solutions. The scenario was the following:

  1. On Monday, you install PostSharp in ProjectA, get the latest version at this time, say 4.0.20.
  2. On Wednesday, we release 4.0.21.
  3. On Thursday, you install PostSharp in ProjectB, get the latest version at this time, that is 4.0.21.
  4. You have both 4.0.20 and 4.0.21 in your solution and you need to solve the mess manually.


There were even worse scenarios:

  1. On Monday, you install PostSharp in ProjectA and ProjectB, get the latest version at this time, say 4.0.20.
  2. On Wednesday, we release 4.0.21.
  3. On Thursday, you install PostSharp.Patterns.Model in ProjectA, get the latest version at this time, that is 4.0.21. Your PostSharp package gets upgraded to 4.0.21 in ProjectA, but not in ProjectB.
  4. You still have both 4.0.20 and 4.0.21.


Unfortunately, this was the default behavior of NuGet. We finally fixed this situation:

  • If you install a new PostSharp Pattern Library in a project that already contains PostSharp, we will install the same version of the new package as the existing version of the PostSharp package.
  • If you don’t have PostSharp installed in the current project, we will look at other projects in the solution and match the highest version already installed.
  • In case we really need to upgrade the package (for instance if you want to use a 4.1 aspect in a 4.0 project), we will first warn you. Note that in this case, we don’t upgrade other projects in the solution so you will have to fix that manually.

PostSharp Explorer

PostSharp Explorer, the Visual Studio toolbox window that shows you which aspects are in your code, is now more useful. You can orient the panel vertically and horizontally, and it has three panels instead of two for better readability.

Universal Apps (shared projects)

We now properly support Universal Apps, the marketing name for “shared projects”. When you add an aspect to a class that is shared among several projects, PostSharp will try to install itself in all projects that use the shared project. That means that you will be only offered the aspects that are eligible for all importing projects. If you need more fine-grained control, you can skip the UI and use directly NuGet and #if blocks.

Note that Universal Apps support is not available in the currently public preview.

Summary

Visual Studio 2015 opens a new era in terms of IDE extensibility, exposing to third-party extensions all the knowledge the compiler has about your code. At PostSharp, we’re proud to be among the first commercial vendors to fully integrate with the new features and even provide unseen developing experience like with PostSharp Assistant.

Happy PostSharping!

-gael