Category Archives: microsoft

speeding up your TFS CI builds

Entering Hyperspace

If you’re using TFS as your build server for CI builds of .NET projects, you want your CI build to be bleeding fast so devs don’t sit around waiting until their build completes. This is even more the case if you use a gated check-in on that CI build.

The ideal time frame is less than 5 minutes, but as a solution grows and more projects are added it gets hard to stay below that time limit without tweaking the build. With a CI build in this case I mean a build used to check if all code compiles, is integrated with other code and all unit tests pass on it.
This build is not used for deployment. There should be a separate build for that.

So what are the time sinks here in a standard TFS build?

It helps if you know what’s it’s doing, even though it’s pretty straightforward. First your code is fetched from TFS. A local workspace is used on the build server and all files are retrieved. Then the VS solutions build with MSBuild. Code analysis is performed if requested, unit tests run, outputs are copied to your drop folder and build reports are published.

Here are a number of things you can do to speed this up:

  • Get only the latest changes, not the full code base every time by not completely cleaning up the workspace. If you only clean up the outputs, it takes a lot less time to update the workspace. The more code you have, the more this counts.
  • Code analysis is CPU intensive and slows down your build significantly. Make sure you set this to “as configured” in your build configuration, so it doesn’t run on projects that you don’t want analysed. Then configure your projects in Visual Studio that need CA, and disable it for the rest.
  • In the Source and symbol server settings, set “Index sources” to false for the CI build. This feature includes source information into your PDB files which makes things easier to debug later on, but since we’re building strictly for a CI build we don’t need this data afterwards.
  • Disable copying output files to the drop folder. The output of the CI build shouldn’t be used for any deployments, so this can all be skipped to speed up the build.
  • Look for slow tests. Often these are integration-like tests which will be causing disk I/O by manipulating files or accessing a database etc. You can disable them for the CI build only by adding a TestCategory attribute called “Integration” (or whatever you like) and exclude those from the build in the test settings. Another trick is to put all your integration tests in a separate assembly and exclude the tests from running using the test assembly file pattern.  E.g. With *.Test.dll project Foo’s Foo.Test.dll is included, but Foo.IntegrationTest.dll isn’t.
  • Avoid lots of small projects in your solution. Every project will take a few extra seconds to build, so merging them into a single larger project will build faster. Make good use of namespaces instead. For example one assembly for unit tests (or 2 if you take that integration test project in mind) is better than a test project for each regular project.

Pick and choose as needed, but these should give you a considerable boost.
Remember to analyse your build before starting to tweak it. There’s no point in optimizing what’s fast as hell already. A good tool to check out what’s taking so long is the open source TFS Build Explorer. It shows your build steps in a tree-view, including timing info and is a hell of a lot quicker than the default build output from TFS for big builds. Depending on your TFS server version you might have to use an older executable, but they are all available in the download section.

Photo by Éole Wind, cc-licensed.

cool geek (dev) stuff I ran into lately

... "Mr. Droopy Eyes!"

I’ve had this list around for a while and though that most people would probably have heard of this by now so I didn’t see the point in posting about it.
Until last weekend someone on twitter was happy to find out about Chocolatey. So I guess not everybody knows these little gems yet, hence this blog post!

  • Chocolatey: a Windows packages manager of sorts. A bit like apt-get on Debian. It allows you to install a bunch of Windows software and tools from the command line. It’s pretty cool and is super handy to get a (developer) box up and running in no time. It’s also handy to keep your installed package up-to-date with the “cup all” statement. Sweet.
    There’s lot’s of good stuff in the gallery already, so you’ll probably find your favorite tool in there. If not, you can add it yourself because it’s built on the NuGet package manager system, or browse what’s available and find some new gems you didn’t know about yet.
  • I haven’t really used Boxstarter myself yet, but if you’re planning on using Chocolatey for some serious VM Windows installer magic, it might come in handy. It builds on top of Chocolatey and allows 100% uninterrupted Windows installs. Thought it was worth mentioning.
  • ScriptCS: one of Glenn Block & co little open source coding adventures. He thought it would be cool to use C# and the .NET framework to run scripts on Windows using the Roslyn compiler API. No need for Visual Studio, project files, compilers or anything like that. Just the scriptcs executable and a text file with your C# script code. Much like Node.js or Python for example. You know, scripting languages.
    Turns out this idea took off like a rocket in the community and has all sorts of cool features by now, like Nuget integration and script packs for reusability. It’s awesome.
  • : It’s jsfiddle for C# code. It’s a web site where you can type some C# code in a console application, run it and see your output instantly. Great of small bits of test code. It even has intellisense support so it’s easier if to use than LinqPad for this kind of tests apps if you don’t know all the statements by heart.
  • all web dev docs in one place and easily searchable. Contains docs for thing like the HTML5 spec, JS, HTTP, HTML DOM and the most popular frameworks like Ember, Backbone, Angular, Knockout and Underscore. Also language like Python, Node, Ruby etc. In short, useful stuff for any web developer working with a modern stack.

Image by James Vaughan, cc-licensed.

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 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 to 2015 (or maybe even later)?
It’s your shortcut keys that are messing with your keyboard I tell ya!

Update: you can remove the shortcut by following the procedure below, but it turns out this is actually caused by the VS Productivity Power Tools add-in. If you disable the “Align assignments” feature in the plugin’s options, you’re done. The procedure below can be handy to debug other shortcut issues however, so feel free to read on anyway. ;)

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….