Category Archives: microsoft

how to get code from tfs from the command line


Ever wanted to pull an update from the TFS server for all workspaces you have without having to start up the Visual Studio? Well I did. Visual Studio is rather slow in starting up and then you have to navigate to the TFS explorer (clicky clicky) and manually update the workspaces (clicky clicky) and then wait till the whole thing is done and VS becomes responsive again (waity waity).

You have the tf.exe command which you can use from a command prompt, but that requires you to use the VS command line because the right paths are set there. You could set the paths so they are available in all your shells, but that’s not very handy either.

I just wanted a batch script that I could run from any shell, that would just update my workspaces for me. Nice and easy.
Like when I press CTRL-R in Windows (Run) and type getfoo.cmd<enter>, it just makes it all happen for me.

So here’s how I did that:

@echo off


:: Importing VS 2012 command line variables so we can run TF.exe
if exist "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat" (
echo Importing VS 2012 environment variables...
call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"

echo *** Updating TFS workspaces ***

:: Repeat this for all workspaces you want to update.
cd D:\WS\pathtosolutionfiles\

tf get . /version:T /recursive

echo *** Workspace updated. ***

troubleshooting tips for ClickOnce deployment packages


Getting a WPF desktop application deployed from a web server like IIS 7 using a ClickOnce package isn’t a walk in the park I’ve noticed. There are tons of little gotcha’s that stand in the way of your automated ClickOnce application generating script and tips to solve those issues are scattered around the web.
Here’s a list of the tips I found and needed to get a working package deployed:

  • To be able to download the ClickOnce package from a web server, the .deploy extension on the package’s files is used to make sure IIS doesn’t block the download because the types are not allowed or unknown (like dll’s, exe’s config files etc). This is to avoid having to add all those file types to the exceptions on the handlers in IIS, which would be a bad idea anyway as you don’t people to be able to download your ASP.NET dll’s anyway. If you don’t have .deploy, you’ll get “file not found” errors from IIS because it refused to allow the file to be downloaded.
  • If you keep getting an error about the application’s entry-point when you download the package, check if your build output has binaries for a mix of platforms. All references should be “msil”. If you see a mix of “msil” and “x86” for the executable or one of its assemblies that could be the issue. You can see that in your manifest file. Fix this by correcting all projects’ build settings in the solution’s configuration manager in Visual Studio.
  • Mage.exe has its limits. Some of the settings in the application file you’ll need to script yourself. For example the auto-update settings, or the mapFileExtensions to download .deploy files. The PowerShell XML type accelerator is great for this.
  • Make sure no manifest or application files are already in the folder you use to create your ClickOnce installer before running Mage. It will result in a non-working installer.
  • Some general troubleshooting tips.
  • You can find some more tips here.

Photo by Hugo Chinaglia, cc-licensed.

using a web client in powershell

Note, for Powershell v3.0 and v4.0 the Invoke-WebRequest (with curl & wget aliasses) is a better choice now.

PowerShell truly is powerful.
A few lines of script is all you need to perform an HTTP request in a PowerShell script. If the native commands don’t cut it, it’s pretty easy to reach out and harness the power of the .NET framework instead like in the sample below.
As a .NET developer this allows you to write some pretty kick-ass scripts without having to compile a line of code.

I like it.

# Add the necessary .NET assembly
Add-Type -AssemblyName System.Net.Http

# Create the HttpClient object
$client = New-Object -TypeName System.Net.Http.Httpclient

# Get the web content.
$task = $client.GetStringAsync("")

# Wait for the async call to finish

# Use the result
if ($task.IsCompleted) {
  # Do your thing here.
  echo $task.Result
} else {
  echo "Sorry, something went wrong: " + $task.Exception.Message

feed your brain with some interesting podcasts

Eggs and Brains

Podcasts are a great way to pass the time while doing semi-automated and/or boring tasks like gardening, driving your car to work and back, or chores related to keeping your house nice and tidy. As long as the tasks don’t take up too much of your active grey-cell CPU you can devote those free cycles to processing some interesting auditory data making that boring chore less boring while learning something in the meanwhile. Sounds good doesn’t it?

Below I listed some of my main brain-food sources I keep going back to, which are mainly technology and science related. I listen to a lot of Microsoft .NET programming related items (guess what we use at work) and some more general programming related topics. There’s also some science stuff or generally geeky & fun things.

  • Hanselminutes: Microsoftie Scott Hanselman talks about interesting topics with a wide range of guests. Well worth the listen and not quite as Microsoftish as you’d expect. If you’ve seen one of his presentations before you know these are fun to listen to as well.
  • .NET Rocks, which is as stated mainly about .NET and related technologies. Still, Carl and Richard occasionally geek out on completely unrelated topics as well, like renewable power or flying to Mars. One of my favorites, because these shows are not only filled with knowledge but they are also great fun to listen to.
  • Herding Code: programming related podcasts about anything new & hip in the coding world. Low frequency updates.
  • Software Engineering Radio: again varied programming topics, not tied to any specific technology hosting some of the big names in the industry. Cherry pick away from their huge archive!
  • ITConversations: ICT/IT/science related. Great to pick & choose from for some brain-food variation.
  • Microsoft TechEd videos: more good Microsoft stuff. These are videos, but if you convert those to an mp3 file, you can just add them to your podcast list anyway.
  • TED videos: lots and lots of really nifty thought-provoking stuff there. Again something to convert to mp3’s or if you have an Android phone simply download the video’s using the free TEDAir app for off-line access.
  • In Our Time podcasts from BBC Radio. If you’re tired of the IT related stuff try this one to learn something new on philosophy, history, science, culture or religion.
  • Another really good podcast show about all sorts of topics. Excellent brainfood to trigger some new neural paths to form and extremely well produced. Pick up a few of these for a taste, and I’m sure you’ll be back for more.

To easily convert online videos to mp3s you can use snipmp3, video2mp3 or listentoyoutube, or install a tool from this Filehippo list. Plenty of other options out there that do the same though. I use VLC to do this myself, but it’s a bit tricky at times (read: too much to explain right here and now).

So what kind of awesome podcast do you listen to?
I’d be happy to find out and extend my brain-food diet.

Photo by Alesa Dam, cc-licensed.

square brackets not working in visual studio 2010 and how to fix that

Have that thing where your square brackets (aka the [] thingies) don’t work any more when you want to access an indexer in Visual Studio 2010?
It’s your shortcut keys that are messing with your keyboard I tell ya!

So to fix this very annoying little side effect, you go to Tools > Options > Environment > Keyboard from the menu.
Now in the text field to create a new shortcut, press the combo to get your square bracket, which is Alt Gr + ^ in my case (Belgian keyboard). That should show you which command is using up your key combination as a shortcut. In my case that’s Edit.AlignAssignments.

The VS2010 keyboard options.

Then it’s just a matter of looking that command up in the list and smacking the Remove button. That’ll teach it to mess with your shortcuts dammit!

I get the impression that these changes are only saved when you close your Visual Studio instance. So if you have more than 1 open, you have to close the one where you changed the setting in last. Otherwise, you’ll have to do this again. And again. And again….

WAS crashes IIS 7 while searching for unexisting services for msmq endpoints

And now: a no thrills .NET WCF technology post in the hope of saving some developer’s time while trying to figure out wtf is going wrong.

The problem looks like this:

Your w3wp process crashes, or your IIS application pool gets stopped for no clear reason. Restarting it only causes it to stop again after a few seconds.
Deactivating the Net.Msmq Listener Adapter in the service control panel makes the problem stop.

Your Windows event log shows errors like this:

An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/1/ROOT
Exception: System.ServiceModel.EndpointNotFoundException

Message: The service ‘~/foobarQueue’ does not exist.

StackTrace:    at System.ServiceModel.ServiceHostingEnvironment.NormalizeVirtualPath(String virtualPath)
at System.ServiceModel.Channels.MsmqHostedTransportManager.HostedBindingFilter.MatchFound(String host, String name, Boolean isPrivate)
at System.ServiceModel.Channels.MsmqBindingMonitor.MatchQueue(MatchState state)
at System.ServiceModel.Channels.MsmqBindingMonitor.ProcessFoundQueues(MessageQueue[] queues, Dictionary`2 knownQueues, Boolean isPrivate)
at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

What’s happening:

The problem is in the Net .Msmq Listener for the Windows Process Activation Service (or WAS for short). WAS checks all your MSMQ queues on the system and tries to figure out if there are any WCF services that it should poke to start reading the messages in the queues. Problem is in the case mentioned above there are also queues on the system which do not have WCF services that process them. WAS tries to activate a service for this “foobarQueue” anyway, which results in an exception.

And here is how you fix it:

  1. Make sure all WCF services that should be processing queues are in a virtual directory on IIS. For example http://localhost/foo/foobarservice.svc
  2. The queues to process will also have to resemble this virtual directory in the queue-name, like: .\private$\foo/foobarservice.svc
  3. Set your web site’s MSMQ bindings to localhost/foo instead of just the default localhost.
    You do this in the IIS Management tool by right clicking your web site, then click Edit Bindings in the pop-up, select the MSMQ binding and edit the bindings’ information as mentioned above.
msmq binding screenshot


That should do the trick.
Good luck!


how to safely run destructive sql statements

christmas afternoon

This tip is one of those “Why didn’t I think of that before” things when I saw it being used first. You see, sometimes you’re on this production database and you need to run some SQL statements in Microsoft SQL Management Studio. Statements that if you mess them up will end up ruining your customer’s day, and most certainly yours too.
Of course you’ve already taken a backup, but that isn’t perfect. It takes time to restore those and the most recent changes might be lost. The database might also be humongous, making backup & restore operations rather annoying.



You know this! Before you run any statement doing anything destructive on your database, first run the BEGIN TRANSACTION statement. It feels like spring doesn’t it? With fluffy little bunnies hopping around merrily in the green grass and yellow flowers.
Whatever you run next, nothing will actually happen until you run:


If in the meanwhile however that delete statement turns out to act like the Spanish Flue and wipes out half of the precious records stored in your database table, there’s always:


Undo. Restore from last save. You don’t lose a life.
Awesome. More fluffy bunnies.

One thing to keep in mind though. As long as your transaction isn’t committed your statements will be putting locks on rows and perhaps even tables. The longer you keep those, the more chance other people’s queries will have to wait for you to release those locks and might even time out. This is bad. So keep your transaction trickery as short as possible.

For more details on those magical statements, see MSDN.