Visual Studio 2010 RC + ReSharper 5.0 + Xunitcontrib all in harmony….finally. 2

madmen_icon

Working on the bleeding edge is painful. Very painful at times. Throwing away our Team City builds because TFS 2010 didn’t support it really hurt. It was a big woops that I regret.

Moving to Visual Studio 2010 Beta was painful too. Visual Studio worked fine, but no ReSharper made it painful. Even in the early days, ReSharper was not stable in 2010, but after a few months, things look good now. ReSharper and VS 2010 are playing nice together.

There is one last pain point. No Xunit.net test runner. Xunitcontrib provides a ReSharper 5.0 build, but I was never able to get it to work…until now. Previously I was getting the same problem seen by others.

The plugin xunit could not be loaded from "C:\program files(x86)\jetBrains\resharper\v5.0\bin\plugins\xunit.dll" or one of its dependencies.  Operation is not supported.  (Exception from HRRESULT: 0×801311515)

I tried the best I could to right-click | Properties | Unblock all the files in the plug-in, but the “Unblock” never worked. I would get the same error. Going back into the properties dialog, the unblock would appear again. It looked like the unblock wasn’t sticking.

After a quick Google search, I found an alternative way to unblock files. Copy the files to a FAT 32 and back. The block is stripped. Sweet! My USB key is FAT 32, and after a quick copy and back. No more errors! ReSharper sees and runs my Xunit.net tests.

Just a quick overview of how I installed the plug-in:

  1. Close Visual Studio.
  2. Copy the contents of the ExternalAnnotations to:
    C:\Program Files (x86)\JetBrains\ReSharper\v5.0\Bin\ExternalAnnotations
  3. Create a folder:
    C:\Program Files (x86)\JetBrains\ReSharper\v5.0\Bin\plugins\xunitcontrib.runner.resharper.5.0
  4. Copy everything else to the USB key.
  5. Copy it to the folder I just created in step #3.
  6. Open Visual Studio and run all my tests.

Refactor rename on LINQ to SQL Classes 2

This is a quick, dirty work around to renaming the properties of the LINQ to SQL classes. Say you have a simple DBML class you want to rename.

image

Simple enough right? Just click in there and edit the WidgetName to Name right? Wrong! You have code like this.

public Widget CreateNewWidget(string name, string description)
{
    return new Widget {
        WidgetDescription = description,
        WidgetName = name
    };
}

You’re going to abandon all those calls to WidgetName and do a search and replace refactor. That sucks. So rename it to WidgetName2 for now and let all the references break.

image

That breaks our code.

image

Fine for now. Create a partial class for the Widget.cs and add our WidgetName back in

public partial class Widget
{
    public string WidgetName { get; set; }
}

Use ReSharper to rename that property to name.

image

Then delete the partial class, or property and rename the property in the DBML to Name.

Done.

ReSharper Tip of the Day: Peek at opening brace 1

It has been far to long since the last R#TOTD, so to ease back in, I thought we’d take it slow with this one.

If you’re unfortunate enough to have your methods grow beyond what can fit on a screen, or just happen to have the method scrolled off the top of the screen, you can identify those closing braces with ease. When ReSharper goes to match the opening brace for the current closing brace at the cursor, a pop up with a tooltip appears if that brace happens to be out of view. It is very handy in finding closing namespace and class braces.

image

It gets even better in RubyMine with syntax highlighting and a semi-permanent window (i.e. it will stay visible while you scroll). Even though I’m not a Ruby developer by trade, I still use RubyMine for editing all my JavaScript files. The intellisense is great and you get ReSharper-like context refactorings in JavaScript files.

image

WPF Toolkit DataGrid, ColumnHeader Style and Blend 4

I’ve spent the better part of the day trying to figure out how to style the column headers of my WPF Toolkit datagrid through Microsoft Blend. Blend is a great tool and I couldn’t imagine trying to do a WPF application without it; however it is still immature and this could be why I found it so difficult to figure out. It could just be that I’m new to Blend, WPF, and XAML and still have a lot to learn.

I’ll spare you the agony I suffered this morning and jump right into the solution.

We have a pretty basic style for the datagrid at the moment. You’ll have to forgive the visual obfuscation.

Changing the the column header style looked pretty obvious in Blend. The menu walks me through the steps to create a resource for the header style.

Give the style resource a name. In this case I am going to show a pivoted set of data with a set of frozen columns on the left and columns that accept entering data on the right. I give it the name I want and choose its destination.

When the steps are complete, I have a style in the resources dictionary for my window, but something is missing.

I’m not sure if I’m missing a step, but the target type of the resource is the generic IFrameInputElement type. It doesn’t provide any properties to set in the designer.
If I look at the XAML that was created, it doesn’t give it a type.
<Style x:Key="EnterableColumnHeaderStyle"/>

The examples I’ve been seeing have a TargetType property to allow for the attached properties to work properly. I got ahead and add my TargetType property.

As you can see, I’m still learning WPF and XAML.  ReSharper steps in and offers to help out a bit. I am glad to let it. It adds the proper namespace to the resource:

<Style x:Key="EnterableColumnHeaderStyle" TargetType="primitives:DataGridColumnHeader">

It also creates the namespace directive:

I don’t really like the namespace alias, so we’ll change it with the help of ReSharper.

Blend now knows our target type and gives us all the properties we could want to style.

We can do whatever we want with the column header now.

And, just as we’d expect, we get our new style.

We can also apply a style to a particular column.

<wpfToolkit:DataGridTextColumn x:Name="FirstColumn"   Header="Something"  HeaderStyle="{StaticResource FrozenColumnHeaderStyle }" >

ReSharper Tip of the Day: Put into ‘using’ construct. 0

There has been some debate if you need every IDisposable should be disposed. From the documentation IDisposable is used to clean up any unmanaged resource.

Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector.

OK. That’s fine. I totally agree with that until I see DataTable is derived from a class, MarshallByValueComponent, that implements IDisposable. Does that mean DataTable has unmanaged resources? Any way, on to the tip.

ReSharper notices when an object is created that implements IDisposable and it can automatically wrap the usage in a using block. Say you have the following code:

…and want to put it in a using block. Trusty ALT+Enter steps in a gives you the following options:

It is creates a nice using block around the object and all of its usages.

What would really be nice is we could create a warning when we see ourselves using an IDisposible without calling Dispose. That might be more difficult than finding one outside of a using. We could be calling Dispose in a try/finally or somewhere else.

ReSharper tip of the Day: Move Code Left and Right 2

Josh showed us how to slap around our code with CTRL+ALT+SHIFT+UP|DOWN. We can now smack around our markup a little further. In addition to the four fingered up and down bully job, we and take an attribute left or right in the pecking order of the opening tag.

CTRL+SHIFT+ALT+LEFT|RIGHT (right in this case) bumps the attribute over.

If you prefer a more vertical representation of the attributes like the following, the command still works, but less intuitive since left and right actually move it up and down, and up and down move the entire tag up and down.

<CheckBox
     Margin="0,0,0,0"
     Unchecked="DoUnchecked"
     Checked="DoChecked">
     Some Text
</CheckBox>

One last thing to note is you do not need to select the entire attribute. Having the cursor in the attribute you wish to move is enough.

ReSharper Tip of the Day: Agent Smith and Agent Johnson 0

On the advice of a super bright coworker, I installed the Agent Smith and Agent Johnson plugins for R#. Now I’m getting all kinds of new advice and context actions.

ReSharper Tip of the Day:More Reminders 0

I’ve stalled with providing tips for a while. My development at work will pickup and I will soon lots of new tips. As we work into using C# 3.0 I am sure ReSharper will continue to impress. For today though, we have a simple reminder.

Alt+Page Up|Page Down goes to the next ReSharper gutter item.

This just saved me a ton of time. We are currently converting some .Net 2.0 code to target .Net 3.5. In so doing I am going to make use of the new language features. Our domain objects are classes with series of classic properties.

    private string fooberry;
    public string Fooberry{
        get{ return fooberry; }
        set { fooberry = value; }
    }

To convert these to automatic properties I could have copy and pasted {get;set;} after each property name and deleted the rest, but R# made it much easier. Alt+Page Down took me to the next suggest which was to convert to automatic properties. Alt + Enter opened the context window with the first action being convert to auto property. Pressing Enter one last time had it fixed.

    public string Fooberry{ get;set;  }

What made it so effective was I was able to hold down Alt the entire time and press Page Down, Enter, Enter, Page Down, Enter, Enter,etc. until my properties in that file were all changed. Total time to convert 20 properties…10 seconds. Try that with copy and paste. I bet it is a bit higher.

ReSharper Tip of the Day: Reminder, Keyboard Short-cuts Work in Other File Types 0

Just a quick reminder, most keyboard short-cuts work in other files types besides source code. In XML and HTML you can:

  • Ctrl + Shift + / to toggle comments
  • Ctrl + w to expand selection
  • Ctrl + Alt + Shift + Up|Down to move elements up or down.

ReSharper Tip of the Day: Add UsingTask 0

While working in an MSBuild file I notice ReSharper will help you out with using new tasks. If you use one it doesn’t know, it’ll offer to add its UsingTask statement to reference it.

It’ll throw this in at the top of the document.

<UsingTask TaskName="Fooberry" AssemblyName=""/>>

Next Page »