ReSharper Tip #123: Creating new classes and moving them to their own file

As I was writing all the source code for my last post, I relied heavily on ReSharper: first to generate classes for me, then to move them to a new file named the same thing as the class. This is a particularly handy technique if you practice Test Driven Development. Here’s how:

When I write a test, I write the whole thing, even though some of the classes may not exist, like this:

image

By placing my cursor on the class name (the red text) and pressing ALT+Enter, I receive the following ReSharper menu:

image

This generates the class in the same file as the test fixture. This is convenient at first. But, it’ll be impossible to find later, so I use ReSharper to move the class to a new file, again by placing the cursor on the class name and pressing ALT+Enter:

image

Which results in this:

image

Me like!

Reason #467 to use ReSharper: Live Templates

I just learned to use ReSharper’s code snippet feature, called Live Templates. I was looking for a code snippet to generate an NUnit test method. Oddly, despite ReSharper’s support for running NUnit tests, they didn’t see fit to include an NUnit test snippet. (Instead they included templates for the xUnit framework [Fact] and [Theory] methods, so I guess we know what framework they’re using.) So, I just created my own. Here’s how:

Step 1: Open ReSharper’s Live Templates dialog from the ReSharper menu in Visual Studio.

image

Step 2: Navigate to the folder where you’d like to add a Live Template and click the New Template button: (For me, this was the C# folder under the User Templates folder.)

image

(ALT+PrtScn didn’t capture the mouse pointer, but you get the idea.)

Step 3: Give your Live Template a shortcut and description, then enter the same kind of snippet code that you’d put in a traditional Visual Studio code snippet.
image

Step 4: Save your new Live Template and turn it on by selecting the checkbox next to it in the Templates Explorer dialog.

image

(Again, ALT+PrtScn didn’t capture the mouse pointer, but you get the idea.)

So, now, assuming I’m using ReSharper’s IntelliSense (to check go to ReSharper / Options / IntelliSense / General), I can create a test simply by typing “te” and selecting my Live Template from IntelliSense.

image

Sure, you could do all of this in Visual Studio, without ReSharper. In fact, Visual Studio 2010 includes a code snippet to generate tests in their syntax (where [Test] becomes [TestMethod]). But, you would have had to hand edit the snippet XML. Plus, ReSharper also includes Surround Templates (i.e. “surround the selected code in an if/for/try statement, please”) and File Templates (to create that new Test Fixture classes with all the correct NUnit using clause and [TestFixture] statement, for example).

To paraphrase Red Green: If your peers don’t find you handsome, they should at least find you handy.

Birthday WiX Wishes

My birthday is coming in early June. If I could have anything in the whole wide world, I’d take one billion dollars. But, if I could only have something from the whole WiX world, then here’s what I’d like:

I want a WiX project template specific to my environment:

  1. I want the template to nail down all the little things we never/rarely do in our current installers, like checking for the right version of IIS, checking for previously installed versions of the application, etc.
  2. I want the template to be able to install an application in multiple environments.
  3. I want the template to auto-detect the platform, if possible.
  4. I want the template to accept command-line or UI driven properties where auto-detection of the environment is not possible.
  5. I want the template to separate static code from dynamic code (using WiX include files containing project specific information).
  6. I want to be able to point the template at a directory and have it auto-generate the appropriate Feature, Directory, Component, and File elements for installing all those files into a target directory.
  7. I want the auto-generator to understand files with DEV, TST, ACC, PRD in their names and setup conditional components as appropriate.
  8. I want the auto-generator code to work with our build process so that the WXS file can be generated at build time – preferably based on a recursive crawl of a root folder, to minimize the maintenance costs/risks.

Anyone interested in helping me blow out some of the candles?

WCF Service Configuration Editor

So, I’ve been working on a small WCF service for a while now. Everything was going well. I had a suite of tests that ran just fine when I ran the service locally. I built an installer using WIX. And, blamo! When I installed the service on a DEV server, I started seeing all kinds of strange errors. Apparently, the service web.config and the client app.config that worked locally aren’t sufficient once you leave the safety of localhost.

And, as it turns out, those config files are horrendously complex. Fortunately, there is a tool to make editing those files a little easier: The WCF Service Configuration Editor. This tool, which is available on the Tools menu in Visual Studio 2008, gives you a GUI for editing the <system.serviceModel> node of a web.config. Here’s what it looks like:

WCF Service Configuration Editor

Granted, it’s not the most intuitive thing to use. And, I’ve only used it this one time. But, it sure took the hand out of hand-editing the web.config for the WCF middleware service.

Windows SysInternals

Wow! Where to begin?

Windows SysInternals is a free set of command-line and Windows utilities from Microsoft. There are so many of them, and they are so varied, that it’s impossible for me to cover all of them here. So, I guess I’ll pull out a few of my favorites to talk about. But, you should really go get the entire set of the tools, as soon as possible!

(Much of the text that follows is pinched from the Microsoft site. My comments are in italics.)

File and Disk Utilities

PageDefrag

Defragment your paging files and Registry hives! (I use this on all of my VPCs. It runs at boot time. I’m not sure whether it’s compatible with SafeBoot, though.)

Junction

Creates Win2K NTFS symbolic links. Think of it like shortcuts within your directory structure.

Networking Utilities

AD Explorer
Active Directory Explorer is an advanced Active Directory (AD) viewer and editor.

Whois
See who owns an Internet address.

Process Utilities

Process Explorer
Find out what files, registry keys and other objects processes have open, which DLLs they have loaded, and more. This uniquely powerful utility will even show you who owns each process.

Process Monitor
Monitor file system, Registry, process, thread and DLL activity in real-time.

Security Utilities

AccessChk, AccessEnum, ShareEnum

Tools for determining who has access to what. Quite handy when configuring security.

SDelete
Securely overwrite your sensitive files and cleanse your free space of previously deleted files using this DoD-compliant secure delete program.

System Information Utilities

PsLoggedOn
Show users logged on to a system. (Use this when you need to TS onto a shared DEV server, but there are already too many sessions.)

Miscellaneous Utilities

BgInfo
This fully-configurable program automatically generates desktop backgrounds that include important information about the system including IP addresses, computer name, network adapters, and more. (We use this on our servers. But, I also use it on my VPCs to remind me which one I’m in.)

BlueScreen
This screen saver not only accurately simulates Blue Screens, but simulated reboots as well (complete with CHKDSK), and works on Windows NT 4, Windows 2000, Windows XP, Server 2003 and Windows 9x. (Geek humor.)

You’re still here? Why aren't you downloading these tools? Go! Download them now!