PowerShell Unix-style Recently I was on the PowerScripting Podcast hosted by Hal Rottenberg and Jonathan Walz. I had a great time talking about PowerShell from a developer’s perspective and psake, my PowerShell-based build system, in particular. You can find the interview on Episode 56 here. Thanks to Hal and Jonathan for having me on the show.

Now let’s talk PowerShell and scripting for developers. I don’t see a lot of developers using the command line and this surprises me. Maybe it’s my Unix background that attracts me to the command line. Maybe it’s my belief that sustainable, maintainable development is facilitated by a CI process, which necessitates being familiar with the command line. Maybe it’s because the only way to create reproducible results is to automate and the easiest way to automate is the command line. Whatever the reason, I believe that developers should become familiar with copying, building, deploying, and otherwise automating tasks via the command line.

So why PowerShell? PowerShell is a full-fledged programming language focused on object-based shell scripting. Note that I didn’t say “object-oriented”. You cannot create class hierarchies or define polymorphic relationships, but you can instantiate and use objects defined in other .NET-based programming languages (or COM objects). PowerShell is a shell language, meaning that it serves the same role as cmd.exe, bash, tcsh, etc. It’s raison d’etre is automating the command prompt. Manipulating directories/files, launching applications, and managing processes is really straightforward.

Microsoft is investing heavily in PowerShell and providing support for managing Windows Server 2008, IIS7, SQL Server 2008, Exchange 2007, and other Microsoft server products. This means that we are approaching the Nirvana that is end-to-end build to deploy. Imagine getting latest from your source repository, building the code, unit/integration testing the code, building the documentation, labelling the build, and deploying into a QA environment! The entire process is automated and reproducible. You know the exact version of the code that went into QA. When you get the green light to do a live deployment, you give the same PowerShell scripts to the IT deployment team who uses it to deploy the compiled (and QA’d) bits into the production environment! Who best to write these deployment scripts than your friendly neighbourhood IT Pro, who is intimately familiar with the production and QA environments. This is a great collaboration point to get the IT Pros, who will be deploying and maintaining your apps, involved in the development process.

Enough chitchat. Show me the code! Believe it or not, you probably already know a fair amount of PowerShell. Many of the commands you’re familiar with in cmd.exe work in PowerShell. (More surprisingly, many of the common commands you know from bash, tcsh, or other Unix shells also work!) The command line arguments are often different, but the basic familiar commands are there. So try out dir, cd, copy, del, move, pushd, popd, … (If you’re a old Unix hacker, you can try out ls, man, kill, pwd, ps, lp, cp, … Unfortunately there is no grep equivalent built in, which is terribly unfortunate.) All of these commands are actually aliases to PowerShell commands, which are named by VERB-NOUN, where NOUN is singular. For example to get a list of running processes, you run Get-Process, which is aliased to “ps”.

PowerShell is very conducive to experimentation. You can always find out more about a command or alias typing “Get-Help [CmdName|Alias]” or simply “help [CmdName|Alias]” since help is an alias for Get-Help. (N.B. PowerShell is case insensitive.) You can also look for commands by typing part of the command and pressing tab repeatedly. For example, if you want to find all set- commands, type “set-[TAB][TAB]…” to display Set-Acl, Set-Alias, etc. You can also look for commands using wildcards. Type “*-Acl[TAB][TAB]…” displays Get-Acl and Set-Acl.

So start playing around with PowerShell. Learn what it can do for you. Next time, we’ll look at writing re-usable scripts for accomplishing common developer tasks. Until then, happy scripting!

Visual Studio 2008 SP1 and ReSharper 4.1 were happily running and helping me develop software, but I wanted to try out the early drops of ReSharper 4.5, which you can find here. I didn’t want to disturb my existing install. So I went looking for a way to run ReSharper 4.1 and 4.5 side-by-side. JetBrains provides the following installation notes, which gave a glimmer of hope.

http://www.jetbrains.net/confluence/display/ReSharper/Installation+Notes+for+ReSharper

Let me start off by saying that I don’t have any meaningful experience building add-ins for Visual Studio. Everything below was gleaned from JetBrains and MSDN documents. Having gone through the trouble, I wouldn’t recommend this approach due to certain – apparently inherent – limitations. (The biggest limitation is that you can only run Visual Studio from the experimental hive as an administrator. The RANU switches might give you a glimmer of hope, but JetBrains would have to update its install utility to support it, as far as I can tell.)

Honestly, turn back now! It’s not worth the trouble. If you’re really concerned about the cleanliness of your Visual Studio install, I would recommend installing VS2008 and ReSharper 4.5 in a virtual machine. If not, then I would recommend uninstalling ReSharper 4.1, installing ReSharper 4.5, and tolerating any glitches in the early builds. The occasional glitch is probably going to be less annoying than the instructions below!

Remember: ReSharper 4.5 builds are daily builds of a product that is in active development. JetBrains is very upfront about the quality of builds on their daily builds page. Whichever method you choose – experimental hive or regular install – be prepared to upgrade to a later build on at least a weekly or biweekly basis.

Oh, you’re still here. I guess you really want to know about how to install ReSharper into an experimental Visual Studio hive. Don’t say I didn’t warn you.

Let’s take a journey into the black art of Visual Studio add-in development… If you’re developing an add-in for Visual Studio, how the heck do you develop and debug it safely. How do you develop in one copy of Visual Studio and use it to debug another copy of Visual Studio running your plug-in? You use experimental Visual Studio hives. Visual Studio hives are areas of the Windows registry that Visual Studio uses to store configuration information. Visual Studio uses the key HKLM\SOFTWARE\[Wow6432Node]\Microsoft\VisualStudio\9.0 to store its default hive. (If you’re running 64-bit Windows, configuration information is stored beneath the Wow6432Node because Visual Studio 2008 is a 32-bit program. If you’re running 32-bit Windows, the registry path doesn’t contain the Wow6432Node.) If you install into an experimental hive, a suffix is appended to the registry path. For example, we’ll be using an experimental hive called ReSharper. So the registry path is HKLM\SOFTWARE\[Wow6432Node]\Microsoft\VisualStudio\9.0ReSharper. When you launch Visual Studio, you can direct it to the default hive (launch VS normally) or an experimental hive via:

devenv /RootSuffix ReSharper

You can have as many experimental hives as you like. This leaves you free to try out different add-ins, ReSharper or otherwise, in a relatively isolated fashion. The choice of “ReSharper” as my experimental hive name is completely arbitrary. I could just as easily called it Ickyickyickyickypatangzoopboing. (Bonus points if you can place the experimental hive name.) 🙂

Please note that you’ll be mucking around with your registry and in particular, your Visual Studio install. If things go really badly, you could have to re-install Visual Studio or even your OS. Probably not, but this is an unsupported install mode. Use the same care as directly editing your Windows Registry (which is essentially what you’re doing). I’m not responsible for any damage you may cause. No warranty express or implied. Do not wash in hot. Objects in mirror may be closer than they appear… smile_regular

You’ll need to download the Visual Studio 2008 SDK 1.1 – the version of the SDK for Visual Studio 2008 SP1. (It would have been too easy to call it the Visual Studio 2008 SP1 SDK.) You can find it here. The SDK contains tools for managing experimental Visual Studio hives. The one that we’ll need is called VsRegEx, which is a command line tool for creating, modifying, and deleting experimental Visual Studio hives. We’ll be creating an experimental hive called ReSharper by copying our default hive.

Open a Visual Studio 2008 Command Prompt as an administrator. (Shift-right-click on Visual Studio 2008 Command Prompt, Run as… Administrator.)

cd C:\Program Files (x86)\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Tools\Bin
VsRegEx GetOrig 9.0 ReSharper

Be patient. This might take a minute or two. (If you want to delete the experimental hive later, run “VsRegEx Delete 9.0 ReSharper”. Note the space between 9.0 and ReSharper.)

Download and install your preferred daily build of ReSharper 4.5. IMPORTANT: When installing, make sure you disable all Visual Studio integration. We’ll be performing the integration manually in the next step.

Copying InstallExperimentalHive.Proj to the Bin directory of your ReSharper install location. (Mine is at C:\Program Files (x86)\JetBrains\ReSharper\v4.5\Bin).

cd C:\Program Files (x86)\JetBrains\ReSharper\v4.5\Bin
msbuild InstallExperimentalHive.Proj /t:Rebuild
devenv /RootSuffix ReSharper /Setup

Be patient. The last step might take a few minutes.

Create a shortcut to “devenv /RootSuffix ReSharper” on your desktop and mark the shortcut to run as an administrator. (Right-click the shortcut… Properties… Shortcut tab… Advanced… Run as administrator.) Double-click the shortcut and you should see:

ReSharper 4.5 in Experimental Hive

So there you have it. ReSharper 4.5 running in an experimental Visual Studio hive. If you install a new daily build of ReSharper 4.5, you won’t have to recreate the hive, but you may have to msbuild and devenv /Setup steps above. Have fun with trying out ReSharper 4.5!

Do you want the next gen of next-gen applications? Get the Visual Studio 2010 CTP! Which is – according to Microsoft itself – really just Visual Studio 2008 with ReSharper installed.

Visual Studio 2010 == Visual Studio 2008 + ReSharper

Take a close look. (Click on the image above for the full-size image.) The window in front clearly shows Visual Studio 2008 with the ReSharper menu (between “Test” and “Window”) and right-hand ReSharper code analysis bar (yellow square and lines indicating warnings in the file). Even funnier is the window in behind, which is the ReSharper Options dialog (ALT-R-O). This is not a photoshopped image, but an actual screenshot from Microsoft.com.

https://www.microsoft.com/Visualstudio/products/2010/default.mspx

This gave me a chuckle. I hope it brightens your morning too.

My blog has been quiet these last few months. With the economic downturn and various friends’ contracts being terminated, I am busy making hay while the sun shines. I have clients with paying work and so I’m staying busy while the work remains available. I’ll have lots of time for blogging when I’m between contracts. That said, one of my New Years resolutions is to “Never stop sugarcoating the facts without notice”. (Brought to you by the Resolution Randomizer.)

image

Seriously, one of my major New Years resolutions is to blog and screencast more. That means more Becoming a Jedi episodes, a series of posts on psake and using PowerShell as a build tool, as well as some other ideas that are in-the-works. Other things that I’m currently excited about, and you’ll likely find posts about in the coming months, include MEF, ASP.NET MVC, jQuery, multi-step refactorings, Prism/WPF, and convention-over-configuration (in both ORM and IoC) to create maintainable applications.

So stay tuned. More content is on its way.

Oh, DevTeach! How I love thee! Let me count the ways! Thank you to everyone for another awesome DevTeach in Montreal at the beginning of this month. The agile track was well-received and included some of the old guard as well as some fresh new faces. I had wonderful time hanging with many friends, whom I only see in person at conferences. If you’re looking for slidedecks and code from my sessions, you can find them here:

Taming Software Dependencies with DI and IoCSlides (PPTX) and Code (SVN)

Achieving Persistence Ignorance with NHibernateSlides (PPTX) and Code (SVN)

I would like to thank everyone who participated in the Agile Q&A with James Kovacs and Friends. The session was originally proposed and was going to be led by David Laribee, but he fell ill at the last moment and unfortunately missed DevTeach. David has done a marvellous job leading these sessions in the past with more panache and style than I was able to muster, but I hope that participants found value in the discussion. My friend, Kathleen Dollard, put together a nice summary of some of the high points and Oren has some commentary on one of the more contentious points that he made here.

If you missed DevTeach Montreal, we are currently planning DevTeach Vancouver, which will take place June 8 to 12, 2009 at the Vancouver Four Seasons Hotel. I have again accepted the position of Tech Chair for the Agile Track and we are looking for speakers. If you’re interested in speaking, abstracts are due by February 10, 2009 and you can find all the details here. Please take heed of the submission tips! I would encourage you to submit more than four (4) sessions as it is highly unlikely that we’ll be able to use all of your submitted sessions. (If you’re a local speaker – no hotel or travel expenses – then you only need one session accepted.) In the past, accepted speakers have submitted 8 to 12 sessions and had 3 or 4 accepted. (N.B. For DevTeach Vancouver, non-local speakers will be required to present 4 sessions.) I would also encourage you to submit sessions predominantly to one track with a few extras in other tracks. When deciding on sessions, it is easier for one Tech Chair to accept four of your sessions than to have four different Tech Chairs each want one of your sessions. If you have three strong sessions in one track, it is fairly easy to find a single slot for you in another track – hence the extra sessions in other tracks. I have had the unenviable position as agile track chair of wanting a really interesting session from a particular speaker, but the speaker’s remaining sessions are “Introduction to Unit Testing”, “Getting Started with CI and CruiseControl.NET”, and “Using Mock Objects to Simplify Testing”. Those are all great sessions, but when Roy Osherove (who was writing a book on unit testing), Owen Rogers (one of the maintainers of CruiseControl.NET), and Oren Eini (creator of RhinoMocks) submit sessions too, guess who I’m going to have to pick? So hedge your bets. Submit 8 to 12 sessions mostly in one track on topics that you’re excited and knowledgeable about. Thank you in advance for your submissions.

I will be delivering a pre-con at DevTeach Vancouver. So if you’re interested in a full-day session on how to turbo-charge your development process while still creating maintainable applications, then you’ll want to attend Agile Development with IoC and ORM. The cost is $399 CAD (or $339.15 USD) per attendee. (N.B. You get a discount if you attend a pre-con, the conference, and a post-con.)

Agile Development with IoC and ORM

As developers we now have powerful tools in our toolbox, such inversion of control containers and object-relational mappers. But how can we use these tools to rapidly build maintainable and flexible applications? In this pre-con, we will look at advanced techniques such as convention-over-configuration in IoC containers and automapping ORMs to quickly build applications that can evolve over time. We will use test-driven development (TDD) to design and evolve a complete working application with supporting infrastructure during this one-day workshop.

image Tonight, Bil Simser and I had the pleasure of presenting a brief overview of Prism (aka the Composite Application Guidance for WPF and Silverlight) to a crowd of 150 developers at Shaw Court in Calgary. You can find the slidedeck here. If you’re interested in getting started with Prism and related concepts, this is a good set of resources to start from:

Thanks to everyone whom came out. If you have any questions, don’t hesitate to contact me or Bil. If you’d like to find out more about Prism and go much deeper into the underlying technology, there is always Microsoft Tech•Days Canada 2008

Zombie Inc.BTW – Some of you might have caught the inside joke in the slidedeck. For the rest… Bil does not in fact work for Zombie Inc., though he probably wishes he did. He is a big fan of the game Stubbs the Zombie: Rebel Without a Pulse. 10 minutes with Paint.NET and I had a decent looking corporate logo for his fictitious company. It’s really quite amazing what you can do with this free .NET application, though the true Paint.NET master remains Justice Gray.

My first dnrTV episode went live today. I am talking with Carl Franklin about dependency inversion, dependency injection, and inversion of control. I demonstrate how to build a very simple IoC container. My intent is to show developers that it isn’t any thing crazy scary. I talk about how IoC facilitates decoupling dependencies and creating more easily testable software. Check it out!

dnrTV #126: James Kovacs’ roll-your-own IoC container

Feedback is always welcome.

Carl and I plan to do another show focused on IoC containers in the next few weeks. Specifically we’ll be talking about what a full-fledged container offers over and above the roll-your-own. If you have other IoC questions you would like answered on the next show, drop me an email.

I was going sysprep a base image of Windows Server 2008 this morning and followed my own instructions on sysprepping Windows. I went to the installation DVD and couldn’t find sysprep. A quick google later and a bit of poking around revealed that sysprep is now installed by default on Windwos Server 2008. You can find it at:

c:\Windows\System32\sysprep\sysprep.exe

The experience is also streamlined considerably. Simply run sysprep.exe above and you are presented with:

 image

Check the “Generalize” checkbox (regenerates system SID), change the Shutdown Options to “Shutdown”, and click OK. The system will go through the sysprep process and shut itself down. You can now create cloned servers to your heart’s content simply by creating linked servers and booting the clone as originally documented here.

UPDATE: Benjamin Chau noticed that SIDs weren’t being regenerated. Turns out that you need to check the Generalize checkbox to make that happen.

Just realized that I never announced it, but I will be giving a double-header presentation at the Regina .NET User Group tomorrow night – Wednesday, October 8, 2008 from 5:30 to 8:30 pm. You can find directions and registration here.

Session 1: Taming Software Dependencies with Dependency Injection (DI) and Inversion of Control (IoC)
Software inevitably contains dependencies. Dependencies between classes. Dependencies between layers. Dependencies with third-party libraries. How can concepts like dependency inversion, dependency injection, and inversion of control help you tame your software dependencies? Where does an inversion of control container, such as Castle Windsor, come into the picture and do you need one? Can Binsor help you achieve convention over configuration? This session answers all these questions and more…
Session 2: Achieving Persistence Ignorance with NHibernate
Object-relational persistence can be very complex and middle-tier code is often dominated by persistence concerns. Your Customer class probably contains more code related to loading and saving customers to the database than it does actual business rules about customers. Wouldn’t it be nice if you could remove all this persistence-related noise? This session examines why the concept of persistence ignorance is important and how to use NHibernate to build persistence ignorant domain models.

I have a busy calendar of events in the next few months. I’ll post my other appearances in the next few days…

image A Reading from the Book of Armaments, Chapter 2, Verses 9 to 21 (Wikipedia | YouTube):

…And Saint Attila raised the hand grenade up on high, saying, “O Lord, bless this Thy hand grenade that with it Thou mayest blow Thine enemies to tiny bits, in Thy mercy.” And the Lord did grin and the people did feast upon the lambs and sloths and carp and anchovies and orangutans and breakfast cereals, and fruit bats and large chu… [At this point, the friar is urged by Brother Maynard to “skip a bit, brother”]… And the Lord spake, saying, “First shalt thou take out the Holy Pin, then shalt thou count to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once the number three, being the third number, be reached, then lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who being naughty in my sight, shall snuff it.”  — Monty Python

And this shall be my third year as a MVP. I received the official email from Microsoft this morning notifying me that I have been re-awarded. Congratulations to everyone else who was awarded or re-awarded today! A special call-out to some very deserving first-time MVPs… Ben Scheirman, Jessica Moss, and Derik Whittaker. I look forward to another fun-filled year of mischief, mayhem, and software development!