Keyboard Shortcuts for Git in Visual Studio

For my day-to-day tasks, I use Visual Studio almost 80% of my working time. About 99% of my work I commit to git and push to server. This is a lot of commits per day. And Git interface in Visual Studio is very clicky, very mousy. So I spent some time trying to improve this by researchign and adding shortcuts. Here is what I got for the most used actions:

In Keyboard configurationof VS assign the following actions to the following commands

  • Team.Git.GoToGitChanges => Ctrl+G, C (Global) => Opens Team Explorer and switches to Changes view.
  • Team.Git.CommitAndPush => Ctrl+G, P (Team Explorer) => Once the commit message is done – you can slam that to get commited and pushed to the server.
  • Team.Git.Commit => Alt+Enter (Team Explorer) => This mimmicks shortcuts in VSCode

I’m playing a bit more with these and will report here if I come up with any improvements, but so far this makes it all slightly faster.

Also for keyboard shortcuts, namespaces Team.Git.GoTo* is worth exploring for navigation options. And Team.Git.* is just worth looking for options that you do with Git in Visual Studio.

Decotrator Pattern Kata

I was explaining Decorator pattern to a colleague of mine and came up with a little coding exercise, code kata to practice.

Here is the task:

Get a class that always outputs “Hello world”. Surround that string with round brackets and then with square brackets, then with round brackets again. You should have 2 decorators. Each decorator can only add a single set of brackets. Output should be “([(Hello world)])”. Also it should be very easy to change order of brackets or add more brackets.

Here is my stub at it.

Count of rows per table in SQL Server

A lot of times I have to study a new database and count of rows per table has been a great source of info. There are many ways to get number of rows per table, but I’m sick of looking it up every time. So here goes one I prefer:

    SCHEMA_NAME(t.schema_id) AS SchemaName,
    t.NAME AS TableName,
    Sum(p.[Rows]) as [RowCount],
    'select top 1000 * from ['+SCHEMA_NAME(t.schema_id) +'].['']'
FROM sys.tables t 
    INNER JOIN sys.partitions p ON t.[object_id] = p.[object_id]
    t.NAME NOT LIKE 'dt%' 
    Sum(p.[Rows]) desc

Here is a discussion with more ways to do the same thing.

CloudException: Please register the subscription with Microsoft.Insights

While trying to connect Azure Automation and log Analytics I came across this error:

CloudException: Please register the subscription {your sub ID} with Microsoft.Insights

Message is clear, but how do I do this?? Took me a while to figure out.

  1. In your Azure portal head to your Subscriptions, pick the required subscription
  2. Inside of a subscription pick “Resource providers” – you’ll be presented with a list of providers.
  3. From the list of providers pick microsoft.insights and click Register.
  4. This fixed my problem

Protect your your Azure Resources from accidental deletion

Last week I’ve messed up a big time. I was doing Azure Storage Account migrations via a PowerShell script, part of that script was deletion of old resource group. That group was meant to be empty every time because I was moving resources out of it.

At one point script threw exception and last storage account was not moved out of the resource group, but last line of the script was to delete that resource group. And it deleted the storage account. OOOOPSSS!

We had backups of data, but that accident made us think twice about our practices. So as part of a response to that accident we decided to use RM locks on all resources.

Azure Resource Management allows to lock subscription, resource group or individual resource to prevent users from accidentally deleting critical resources. Locks can be CanNotDelete or ReadOnly. Read more about locks in official documentation. If you put a subscription lock it covers all resources and groups within this subscription, but for our purposes this was too generic – you remove a lock and all of your resources are open for accidental deletion. So I settle on adding locks per Resource Group.

Continue reading

Amazon Alexa. First impressions

Recently I purchased Amazon Alexa, just for fun. Initially wife wanted a radio or a Bluetooth speaker on kitchen. And Alexa was cheap enough to use as a speaker/radio.

On the first day I’ve asked it a bunch of questions and got a lot of rather disappointing “hm.. I don’t know that one”. Yeah, sure it can tell me weather and news briefing. Kitchen timer is rather useful (unless it mishears you and resets it instead of pausing).

I’ve tried a bunch of skills and none of them were particularly good/useful. Idea was to get a cook-book, but nothing descent was available (there are Allrecipies, but not available in UK).

And for listening to a music – that’s another disappointment. Turns out that all my MP3s I’ve collected over the years are worthless here. To be able to listen to a music I need to purchase one of the streaming services (Amazon Music or Spotify). But I want my music, not streamed. I’ve wasted a lot of time searching for solution. There were a few options. There is Synology (of which I’m an owner) skill, but that’s been only released in October 2017 and not yet available. There is Plex server, but the this skill does not let me stream music through Alexa – it is a merely voice remote control for other existing player.

I’ve seen a lot of developers telling their way of enabling Alexa to stream their music, but none of it was ever approved to Alexa skills market (why would Amazon allow for that? they sell music service!). And to get that working, involved a lot of work that I did not want to do.

Another thing that I did not like was a way of activating the skills – I had to call it by name and ask for the exact specific command: i.e. Alexa, tell Hive to boost heating to 21 degrees. That’s rather a mouthful. Given I does not always work from the first time, I can turn on my heating on my phone faster. I’d much rather prefer Alexa, boost heating, but that did not always work. Same goes for other skills: Alexa, ask Radioplayer to suggest a station or Alexa, ask [skillname] to do [command-name].
Well, yes, I understand that we are dealing with computers here where precise commands are required, but the last thing I want to remember is that silly skillname to get myself some radio. Granted, there is a built-in TuneIn online radio with hundreds of radios to choose from – problem here to remember (or rather know) the station name I’d like to listen to.

Also I was hoping for advertised shopping list and to-do list to be voice-activated. But my preferred service Wunderlist was supported as a second-class citizen and to add items to my Groceries list I had to go like Alexa, tell Wunder Link to add eggs to my Groceries list. I was hoping for Alexa, add eggs to my shopping list but that is not available. However had a better integration, but I’m not sure I like it better. I grew fond of Wunderlist simplicity and bells-and-whistles of Todoist are overkill for my simple lists.

Anyway, that device turned out to be not that useful as I was hoping it to be.

Here are useful stuff for myself (your mileage may vary):

  • Kitchen timer (rather expensive one)
  • Bluetooth speaker (again, on the expensive side)
  • Online radio (if you know stations names you like)
  • Hive heating control (somewhat flaky)


  • Unable to play my music without buying a service subscription
  • Voice commands have to be in certain format and having to remember application names and exact format expected is a pain
  • Not clever at all when answering non-wiki questions

So now I’m pondering should I try and build a skill for Alexa (and what should it be?) or just send it back to Amazon?

GitVersion vs dotnet pack on VSTS

Last night I run into a problem with GitVersion and dotnet pack command while running my builds on VSTS

The probem came up when I tried to specify a version number I’d like the package to have. There are answers on SO telling me how to do it and I’ve used it in the past. But this time it did not work for some reason, so I had to investigate.

Here is the way it worked for me.
To begin, edit your *.csproj file and make sure your package information is there:

    <Description>Some description</Description>
    <PackageReleaseNotes>This is a first release</PackageReleaseNotes>
    <Copyright>Copyright 2017 (c) Trailmax. All rights reserved.</Copyright>

Continue reading

PC wakes up at night

Microsoft has a strange idea that anybody would want their PC to be woken up during the night to do the maintenance task. WHY???

All my PCs have encrypted drives and password is required for windows to boot. So even if PC manages to wake itself up – it is stuck on password prompt. DUH!

Way to check it:

powercfg -waketimers

If you see Reason: Windows will execute 'Maintenance Activator' scheduled task that requested waking the computer.

Head to Control Panel -> Security and Maintenance -> Expand Maintenance. There will be an option to disable waking your PC for Maintenance.

And here is another discussion with some answers, though people do report that Windows 10 is notoriously bad for ignoring any/all of these settings and you will still get your PC woken up at night, barring all but unplugging it from the mains

And another discussion with a lot of details.

User impersonation in Asp.Net Core

I’ve blogged about user impersonation in Asp.Net MVC three years ago and this article has been in top 10 of most visited pages in my blog.

Since Asp.Net Core is out and more or less ready for production, it is time to review the article and give guidance how to do the same thing in Core. Approach have not changed at all, we do same steps as before, only some API been changed and it took me a bit of time to figure out all the updated API parts.

Impersonation Process

Impersonation is when an admin user is logged in with the same privileges as a user, but without knowing their password or other credentials. I’ve used this in couple applications and it was invaluable for support cases and debugging user permissions.

The process of impersonation in Asp.Net core is pretty simple – we create cookie for potential user and give this to the current admin user. Also we need to add some information to the cookie that impersonation is happening and give admin a way to go back to their own account without having to log-in again.

Continue reading

General Rules When Building OSS Libraries

In the last couple years I’ve built a few libraries for public and internal consumption. Mostly these have been internal things, but they are not much different from OSS libraries.

So far the most popular libarary I’ve released open-sourced is Cake.SqlServer but I’m mostly proud of NSaga though it is not as used, mostly due to lack of marketing effort on my part. Both of these are still on v1.x though these are young libraries – both under 1 year of age at the moment of writing.

In a sense libraries for internal consumption are easier to build – you can break things and then fix the broken things in the downstream projects (or tell people how to fix). If your library is publicly released you need to be much more careful in how you handle breaking changes and how you define your public API surface. Semantic versioning is supposed to help you manage the breaking changes, but you still need to minimise the possibilities of breaking things for other people. If you are not careful and break a lot of stuff, people will be pissed off and eventually move away from your library.

While building OSS libraries I had to excersise a lot of care to cater for wider audience and rules I draw below are mostly coming from OSS. So here they are:

.Net Framework Versions

You need to consider what framework version you build for. Nature of .Net framework – every version is an increment on the previous, so library built for v4.5 will work in v4.6.1. But not the other way. So you need to pick the lowest version of .Net you’d like to work with and stick with it. I think it is fare to say that no currently developed project should be below v4.5. There is no reason to stay on lower version and upgrade from v3.5 is relatively painful. So my rule of thumb is to target v4.5 as a baseline, unless I need framework features that are only available in later versions.

Continue reading