C# Interpolated Strings in older .NET frameworks


When targeting a .NET 4.0 or 4.5 project it's not possible by default to use the Interpolated Strings and their FormattableString and IFormattable counterparts. By default

But, this is only because these two types didn't ship with the older version of the .NET Framework. If you make sure these classes are available to the C#6 compiler, it will happily produce an assembly which is compatible with the older versions of the .NET framework, since these interpolated strings are a language feature and not dependent on the Common Language Runtime.

You'll need these classes to pass a CultureInfo in order to satisfy Code Analysis 1305.

Someone beat me to creating a NuGet Package of the classes required, which makes this as simple as running:

install-package StringInterpolationBridge

C# 6 Interpolated Strings and Code Analysis (CA1305)

C# 6 introduces a new concept, Interpolated Strings, sort of the compiler version of String.Format. It's a great way to ensure that the compiler checks that your variables actually exist and that you're passing the right number of 'm.

And as with String.Format it's important to pass the correct CultureInfo to it to ensure that you're showing the right date formats, "." or "," as decimal separator etc.

By default it will use the CurrentCulture, which makes sense when formatting data to display them in the User Interface. In many other cases, however, you'd want to format your data in Invariant form, when writing to a file, calling an external service or storing data in a database.

To ensure that you, as a developer have thought about this, there is a Static Code Analysis rule that ships with Visual Studio, CA1305: Specify IFormatProvider. Unfortunately the documentation of this rule has not been updated to show how to supply the IFormatProvider or CultureInfo to an Interpolated String.

There are multiple ways to handle this, but all involve casting the Interpolated String to a FormattableString or a IFormattable. The way that's the most straightforward is to cast the formattable string and then call .Tostring on it:

FormattableString fss = $"Hello, {name}";

While this works, it'll probably drive every developer crazy, having to create a variable or being creative with casting:

((FormattableString) $"Hello, {name}").ToString(CultureInfo.InvariantCulture);

which won't make your code easier to read one bit, I'd almost stick to String.Format ;).

There is a very interesting trick which combines another C#6 feature, static imports and the calling the Invariant method:

using static System.FormattableString;
string x = Invariant($"The value is {m}");

Unfortunately, Microsoft decided to not create a static CurrentUI nor the static Current variant, which I feel is a shame. Or course it would not take much to create your own versions of these static methods:

public static string Current(FormattableString formattable)
    if (formattable == null)
        throw new ArgumentNullException("formattable");
    return formattable.ToString(Globalization.CultureInfo.CurrentCulture);

public static string CurrentUI(FormattableString formattable)
    if (formattable == null)
        throw new ArgumentNullException("formattable");
    return formattable.ToString(Globalization.CultureInfo.CurrentUICulture);

See also:

Connecting to TFS from any version of Visual Studio


I've written a couple of blog posts on this subject before and thought it would  be nice to consolidate them into one big post now that Visual Studio 2013 is about to be released. There are 3 major things to consider when connecting to TFS from an older version of Visual Studio.
  • The version of TFS you want to connect to
  • The version of Visual Studio you're connecting from
  • The version of Windows you're running
In this blog post:
  1. Connecting to Team Foundation Server 2015 or Visual Studio Online.
  2. Connecting to Team Foundation Server 2013.
  3. Connecting to Team Foundation Server 2012.
  4. Connecting to Team Foundation Server 2010.
  5. Configuring the MSSCCI provider for Visual Studio
  6. Connecting from Visual Studio 2005, 2008 or the MSSCCI provider
Since writing this post, Microsoft has produced an updated piece of documentation (which is already behind in some aspects) that describes most of the client/server combinations. One thing it adds which I haven't described, is the list of features that are available depending on your version of Visual Studio/TFS.

If you're having issues connecting after updating, it might be required to clear your local client cache to clear up certain issues like this one. Either the official way or the hard way.

If you also want to install the Team Foundation Server Power tools to match your Visual Studio/TFS version, check out this separate post.

Update: Updated download links to the final version of Team Explorer 2013.
Update (13-11-2013): Updated download links to the final version of Visual Studio 2012 Update 4.
Update (25-11-2013): Added information on client cache and feature docs.
Update (6-1-2014): Added update for VS2010 for Windows 8 and Visual Studio 2012
Update (21-1-2014): Added update 1 for Visual Studio 2013
Update (25-8-2014): Added update 3 for Visual Studio 2013
Update (21-7-2015): Added update 5 for Visual Studio 2013 and Visual Studio and TFS 2015. Since Visual Studio 2013 Update 5 contains updates to handle TFS 2015 Team Project Renames, it's recommended for anyone connecting Visual Studio or MSSCCI 2013 to TFS 2015.
Update (22-7-2015): Added update 5RC for Visual studio 2012.Since Visual Studio 2012 Update 5RC contains updates to handle TFS 2015 Team Project Renames, it's recommended for anyone connecting Visual Studio or MSSCCI 2012 to TFS 2015.
Update (26-8-2015): Replaced Visual Studio 2012 Update 5 RC with the final version.
Update (30-8-2015): MSSCCI 2013 now also supports Visual Studio 2015. But since there is no stand-alone download for Team Explorer 2015 you'll need to install Visual Studio Community Edition or Express if you don't have a license for Visual Studio Pro or better.

Turn off Visual Basic 14 language features in Visual Studio 2015


If you're on a team that's doing solution round-tripping between Visual Studio 2013 and 2015, then it's usually a good idea to turn off the latest Language features. That way you don't break the 2013 users, yet are able to use all the other new goodies that 2015 brings.

The C# Project Properties offer a nice UI feature to do this, even though it's well hidden in the property pages.

Visual Basic .NET doesn't have the UI, but it does have the same feature. When you change the property in the UI of the C# project it sets a <langversion> tag in your project file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

Doing the same thing in your .vbroj actually has the desired result:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

This is the result:

NDepend 6 offers native integration into TFS 2013


When Patrick Smacchia contacted me a couple of weeks back to look at his new TFS support for NDepend I was very excited. We've integrated NDepend through commandline calls  with numerous clients and though that works, it's not very easy to get trend analysis or act upon the findings in the build.

The new integration is native, offering full and fast integration without the need to redo any calculations or compilation on order to get the most out of it. Over the last two weeks I've worked very closely with Patrick to make the integration even smoother, enabling Code Coverage results for the Visual Studio Test Runner and adding a few tweaks here and there.

You can now download the latest Release Candidate and give it a spin. 

With the new version NDepend also integrates into Team City and Sonar, making it a new standard among code quality tooling.

I'm sure I'll be working with Patrick in the future to help enable VSO, Team Build 2015 and Build vNext support. If you have any thoughts on how we could make the integration even better, then please reach out.

Time for a new laptop


It's time for a new laptop, that means time to figure out what to re-install and what to let go of. I'm always curious to what others run on their machines to boost productivity, and really enjoyed the blog posts from, for example Scott Hanselman and Roy Osherove (back in 2010) on this topic. I through, as I need to create a list of items to download and install anyway, I might as well make it public.

So here we go:

Windows 8.1 Professional 10
Lenovo released the drivers for Windows 10 for the Carbon Touch X1. These also solved a couple of issues I had with the Windows 8.1 drivers, including Youtube videos that would cause 100% cpu and stuttering (due to failing hardware decoding), Photoshop crashes (due to old video driver) and flaky wifi. I've used the default drivers from Windows Update as much as possible, amending it with the drivers from the Lenovo website where none were offered by Microsoft.

Office 365 2016
Office 365 offers both cloud mail, storage and licenses for Office on my machine. It's one click streaming install is an easy choice.

TechSmith SnagIt & Camtasia
As a blogger, StackOverflow user, presentation builder, guidance author, SnagIt the bomb. Quickly grab a piece of your screen, annotate it, do basic editing and either upload it to the cloud or copy/pate it directly into your latest StackOverflow answer.

The on-screen video recording features are very useful as well, as often a short video says more than static pictures.

Camtasia then helps put these all together and makes it look professional.

Playing around with Windows 10, creating rescue environments, demo-on a stick, Rufus helps you create boot images on USB sticks using ISO files downloaded from your MSDN subscription. It's easy to use, has never let me down and can create drives that support both old-style BIOS and UEFI.

Free Download Manager
Ever had to download a Brian Keller VM?! Free Download Manager is *the* tool to do it. Though I always turn off Torrent support, not sure what company policy would think of having that running. Plus it prevents me from accidentally downloading stuff I shouldn't be.

NetSetMan Pro
As a consultant I generally visit different clients, all with different networks. Some offer a simple guest network, others require  Proxy setup and each of course has its own printer. NetSetMan Pro allows you to manage your network settings and windows defaults and can automatically switch the settings based on the Wireless networks in range. Quite useful. It's the best out of a bunch I've tried. One very useful feature is its ability to run on the log-on screen. So if you recently changed a password or need to log on using a user that hasn't used your machine before out of the office, it can fire up your VPN or connect to a wireless network to do just that.

As an avid Kindle user I have more ebooks than I have space on my Kindle. Especially IT books with lots of screenshots take up a huge part of your limited device space. Calibre catalogs them all, fixes their metadata (so you can find them again), links them to Goodreads and Amazon so your ratings are for more than you alone. It's especially nice for books from Leanpub, HumbleBundle and Kickstarter books.

Unfortunately it still isn't the best reader on your laptop or tablet. So I have the Kindle for Windows app installed side-by-side.

Last time I had to burn a DVD is some time ago... So I've opted for this great free solution. No expensive licenses for features I'll never use. Creating audio CD's and backing up pictures for friends is just about what I use this for.

Ever look at the clock during a late night coding session and find out that it's already 3:30am? The blue light from your screen prevents your body from making the right substances to make you tired. This can be a blessing (if you need to finish a presentation before tomorrow morning) or a curse (if you need to give an already finished presentation tomorrow morning).

F.lux detects your place on earth and adjusts your screen brightness and tint according to the position of the sun.

Don't forget to turn it off when editing photo's or video's (or capturing screenshots), but keep it running at all other times. It's helped me get a much better sleep rhythm. There is a similar app called Twilight that does the same thing for your Android phone.

Converting audio formats is one of those things you'll need not to do often. Fre:Ac doesn't have the most up to date UI and it isn't as good as some of the commercial available alternatives, but hey, it's free! And it does what it needs to do, produce great quality audio files in every format imaginable.

Along the same lines as Fre:Ac and Calibre, Tag&Rename is one of those very useful tools to make sure the metadata on your files matches it's contents. That your Plex server will be able to group and index your music effortlessly and your car's stereo player won't crash on malformed ID3 tags. I've tried free alternatives, but the integration into Amazon for cover downloads and metadata, plus the easy formatting macros to both rename files and extract tags from existing names makes this the best tag editor out there.

Many years ago, when Winzip was the bomb, it was the only tool you needed, then Rar came along and in short time the different compression formats exploded. Winzip turned from a simple tool into a complicated wizard and WinRAR never releases a free version (though it's trial ran forever). Then 7zip came along. It can decompress all formats I've encountered in the past years, it's fast, it has the ability to encrypt the file names in the archive (to mail files past pesky mailservers) and has one of the best compression ratios int he industry. Did I mention that it's free and simple to use?

When you're installing so many free tools (and probably a java runtime, some browser plugins and Acrobat Reader), you'll be unchecking a lot of checkboxes for browser toolbars, explorer extensions and other nasty tools that make Windows and your browsers unresponsive and do stuff you never wanted it to do.

If you don't install this for yourself it's for your parents, brothers and sisters outside of IT and your extended family as it helps them keep you away. It's like the apple in the old saying.

Unchecky does one thing. It unchecks the checkboxes that install all kinds of "extra's". And that makes it one of the required tools in my tasktray.

With all the information breaches, SSL Bugs and phishing out there, strong passwords and different ones for each site are a must. I've always prided myself in being able to remember a lot of phone numbers, but the sheer amount of passwords nowadays is just too much to either remember or keep secure.

So I trust in lastpass. And in Yubikey... and pray they'll never be compromised. Their security model ensures that your password is never sent over the wire and they use very strong security with lots of cycles to slow down anyone who wants to brute-force your storage.

Their apps are available for all platforms and they offer a plugin to integrate into your webbrowsers. The plugin is not the most beautiful in the world, but it does what it is supposed to do. They've been improving the looks quite extensively lately, so I'll keep my fingers crossed.

Controlled Vocabulary
I'm not sure how many email-lists you are still on, I understand they're a bit a thing of the past with companies moving to Yammer, Slack, HipChat and other services. Yet I find myself on a mailing list for Microsoft ALM specialists, The ALM Rangers, Scrum.org trainers and multiple beta programs.

Controlled Vocabulary is a tool that helps in categorizing email with tags so others can route your emails based on rules. It requires some discipline from all people on the list, so it may not work for yours, but if people use it correctly it's a great way to separate the important messages from the less important ones. Not sure about your mailbox, but I generally receive 100's of emails a day and spending time on the right ones is paramount to a decent productivity

Paint .NET
This little free paint replacement with enough power to do simple image manipulation is powerful enough for many of the small things I do with images while developing and for presentations. I sometimes long for the power of Photoshop, but the price has always felt prohibitive. Now with the Creative Cloud offer, I may switch, as upgrading my old Lightroom 4.0 license will cost me as much as a year's worth of both Photoshop CS and Lightroom.

Until then, Paint .NET will be my go-to tool for small image work.

Atom (or Visual Studio Code)
Notepad is sooooooo 1993... In comes Atom. Free alternative to Sublime Text and the basis for Visual Studio Code. It's a multi tab text editor with all the features you could wish for. From extensibility to syntax highlighting to intelligent XML auto-suggestions.

Other stuff
Other tools, more in the development space, haven't changed much since my last tools of choice posts (Helpful Visual Studio Add-ins, My must-have extensions for Visual Studio 2013)

  • Visual Studio 2013 Update 5 RC
  • Visual Studio 2015 RC
  • Resharper 9.1.1
  • Visual NDepend 5
  • Reflector .NET 8
  • Team Foundation Server 2015 RC
  • Team Foundation Server Power Tools 2013 (waiting for the 2015 release)
  • SourceTree (for more advanced git trickery)
  • PoSH Git (for easier git command lines)
And the usual bunch of tools:
  • Google Chrome and Drive
  • OneDrive
  • Firefox
  • Skype

What can I say about these.

Temporarily bypass Bitlocker encryption requirement for removable devices


Microsoft allows a system administrator to set a policy that requires the users to enable Bitlocker encyption on any device before it can be written to. This is a pretty foolproof system to ensure that company data is always encrypted (except that you can always turn off encryption on a device, which will decrypt (not destroy) the data.

It's pretty simple in it's use and only mildly frustrating as you're waiting for the device's first encryption (it can take quite a while on a 1TB portable drive).

Except when you want to put something on your Kindle, old iPod Touch or in my case today on a USB flash drive in order to make it UEFI boot compatible.

Luckily it's quite easy to temporarily (until the policy gets refreshed) disable this through a small registry tweak (which requires you to run as local administrator).

Simply import the following to turn off the policy check:

Windows Registry Editor Version 5.00


Import this snippet to revert back to the secure state:

Windows Registry Editor Version 5.00


This is quite probably a breach in the security policy of your company. Use at your own risk.

Search This Blog


Most Reading