Wednesday, October 17, 2012

Add the Visual Studio Command Prompt to VS2012

Several times this week, I wanted to launch a Windows command prompt (not the VS Command Window which is different) while in Visual Studio 2012. More specifically, I wanted to open the command prompt in the directory of the item I had selected in Solution Explorer. I swear I could do that in VS2010 but I can’t find that in VS2012.

I gave up and did a two step dance:

  1. Right-click selected folder | “Open Folder in File Explorer” [alternatively: “Open Containing Folder”]
  2. Ctrl-Shift-right-click | “Open command window here”

That works for most purposes although I don’t benefit from the VS-specific environment variables.

Then I stumbled across an old blog post by V K Sumesh (2008) that describes how to add the Visual Studio Command Prompt (VSCP) to the tools menu. That’s worth a read for background. I’ve updated the steps here for VS 2012 and to suit my preferences.

Add VSCP to the Tools menu

  1. Tools | External Tools …
  2. Click [Add]
  3. Title: Command Prompt
  4. Command: C:\Windows\System32\cmd.exe
  5. Arguments: "%programfiles%\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"
  6. Initial directory: $(ItemDir)
  7. Click [Move Up] to position the command (I put mine at the top)

In step #5 I’ve specified vsvars32.bat, a batch file that supplements the Windows environment variables with environment variables for the .NET framework tools.

In step #6 I picked the “Item directory” because that’s my preference but the dialog offers other choices which may suit you better.

Here’s what it looks like before I click [OK]


Use it

  1. In Solution Explorer select the folder or item where you want the command window to open
  2. Tools | Command Prompt

Hope that helps. Let me know if there’s a better way.


The “Open command prompt” feature that I remembered from VS2010 came by way of the Microsoft “PowerCommands for VS 2010” extension.

Apparently the 2010 extension works for VS2012 as well. Take note: there are a ton of features in that extension, many of them already in VS2012. I was worried about redundancy and bloating my context menu with ever more rarely used options. But it seems well-behaved and you can disable features you don’t want via Tools | Options | PowerCommands. It’s a worthy alternative to the technique I described above.

Tuesday, October 16, 2012

Update a NuGet package with MSBuild

In this post I’ll show you how to add a prebuild MSBuild target to your project that updates a NuGet package in the project when you rebuild.


We ship a zip file of BreezeJs samples . Some (soon to be all) of them rely on a NuGet package to supply the Breeze JavaScript files and other dependencies.

Breeze changes regularly (for the better we think) and so must the NuGet package version.

Our sample solutions are set to restore all NuGet packages so that we don’t have to ship them as part of the zip. Unfortunately, the “packages.config” file that identifies the BreezeJs NuGet package is stuck with the old version. Package restore simply grabs the old version of that package.

We could not find a way to markup the items in the packages.config so that NuGet restored the latest version of the package. It always restores the exact version identified in package.config.

We don’t want to modify those samples every time we update the NuGet package. We want the samples to update to the latest BreezeJs automatically.

We don’t want to update every package in the solution; just our BreezeJs package and its dependencies.


We added a prebuild target to the bottom of the project file. The target invokes nuget.exe from the command line, telling it to update only our package (“Breeze.MVC4WebApi”) and its dependencies.

We know that nuget.exe is in the project sibling “.nuget” directory because that’s where the package restore facility puts it.

Here’s our target:

<Target Name="BeforeBuild">
  <Exec Command="&quot;$(SolutionDir).nuget\NuGet&quot; update &quot;$(ProjectDir)packages.config&quot; -Id Breeze.MVC4WebApi" />

Sunday, October 7, 2012

Tribute to Code Camp

Let us sing praise to code camps everywhere and in particular to the Silicon Valley Code Camp here in the San Francisco bay area. I’m just home from SVCC which, at 2500 attendees, is one of the largest (if not the largest) code camps in the country. At any hour I could choose from twenty-five sessions touching a wide range of technology interests.

Yet SVCC retains an intimacy and immediacy unmatched by formal conferences of equal size. Like all code camps, SVCC is free to everyone, supported by an army of volunteers and industry sponsors (thank you, sponsors!). People flock to camp to share their enthusiasms and discover something unexpected. The mood is jolly and infectious.

It’s a wonderful place to speak. It’s a terrific opportunity to learn to speak. Never spoken publically before? Do you have the urge? Feeling a little shy? Don’t hold back … bring your talk to a Code Camp. Code camp welcomes all speakers and every speaker, novice or veteran, finds a respectful audience. Code Camp is the place to lose your stage fright and speak your mind.

You will connect! At many conferences, the room is dark, the faces are lit by laptops, and it is painfully evident that many in your audience are twittering, emailing, or doing something other than listening. At Code Camp, the lights are up and they’re paying attention. They interrupt constantly with questions and observations. I know exactly how my talk is going, what points are resonating, which are falling flat. I go where my people want me to go. My talk becomes conversational. My nerves calm, my fear of failure dissipates … I’m having a conversation. You really must try it!

Are all the talks good? No, of course not. You’re bound to think, “geez, I could do better than that!” Maybe you can. You won’t know until you put yourself on the line … and you owe that experience to yourself.

Even the inept talk has much to offer. When the speaker cares … and at camp they really care … something of interest always bubbles to the surface. I imagine myself trying to tell the same story, wondering how a different image, a different phrase, a dramatic gesture might make it more compelling. I always come away with some fresh tidbits on the speaker’s subject and a page full of ideas for improving my next presentation.

Finally, a big thank you to the organizers and volunteers at SVCC. An effective conference is no accident. It’s a lot of details and asses-and-elbows. I don’t know about you but I’m always either lost or anxious about getting lost. Driving onto the sprawling Foothill College Campus, a volunteer greets me at the gate and points the way to 4 parking lots, all free thanks to sponsors. Signs every 100 yards along the long winding road lead me confidently to these lots. I step out of the car and hundreds of signs, on the ground and on walls, always in sight, guide me to registration and from there to session rooms. There’s a map on the back of my badge.

Lunch for 2500? No problem … lines move swiftly through the hall; in minutes I’m out on a grassy knoll (not the grassy knoll), under sunny skies, deep in conversation.

For us, speakers and attendees, the day flows effortlessly; we are oblivious to the many things that are going wrong. Maybe the coffee is late. Or all the badges disappeared. The volunteer team scrambles and all is set right. The illusion of calm is sustained.

It’s a magic act made possible by hard work, years of organizing experience, and tons of passion. I urge you to be a part of it. Attend a code camp, speak at a code camp, volunteer at a code camp. You need code camp and code camp needs you.