Managing Vsix Deployments with Powershell

tl;dr – VsixTools fixes the ‘Invalid Multiple Files in VSIX’ issue on the Visual Studio Gallery and lets you set vsix version numbers with Powershell.

I maintain a reasonably large project called SharpGL. This project contains two Vsix packages (Visual Studio Extensions), each of which contains project templates for Visual Studio.

If you have ever worked with Vsix files before you might have noticed that the tools for them in Visual Studio seem a little flaky – but even more so is that Visual Studio Gallery site that you have to use to upload your extensions.

Add more than one project template to your Vsix and try and upload it – this is what you’ll see:


It’s a pain to solve this problem – basically you need to change the folder structure within the vsix file, then change the xml that describes it. Now this is not too much of a problem if you do it once or twice, but if you’re in the situation where you want to be able to build a release of your code rapidly, including extensions, this will seriously slow you down.

Enter VsixTools, a little Powershell script that lets you resolve this issue and as a bonus lets you set the version in the Vsix as well – very useful for scripts that build releases. You can use it like this:

# Load vsix tools
. VsixTools.ps1
# Set the version number of 'MyPackage' and fix the zip issue for uploading to the gallery.
$vsixPath = "c:/MyPackage.vsix"
Vsix-SetVersion -VsixPath $vsixPath -Version ""
Vsix-FixInvalidMultipleFiles -VsixPath $vsixPath

This Powershell script has no dependencies, it’s just Powershell 2.0. Get the script at github.com/dwmkerr/vsix-tools.

It works for package manifests of version 1 or 2 – for anyone who’s lucky enough to have not had to delve into the internals of this that means that it works from Visual Studio 2010 onwards.


Practical AngularJS Part 2

I’m going to be working in F# almost exclusively for a short while, so before I throw myself into that I wanted to wind up my Practical AngularJS Part 2 article. It’s ready to rock here:

Practical AngularJS Part 2 – Components of an AngularJS Application

In this article we get a brief introduction to what’s in the toolkit for an angular developers – filters, controllers, services, directives, views and routes. I don’t go into too much detail, we’re just seeing what the different components are. Spread the word, share the article and as always, comments are welcome.


Langton’s Ant in Javascript

Langton’s Ant is a great simulation to write to play with a language. Just today I’ve completed my Langton’s Ant write up and published it on the CodeProject, you can see the article at Learn JavaScript Part 3 – Angularjs and Langton’s Ant.

Langton's Ant

There are some interesting things in the article for angular too – a look at using directives for custom elements, how to handle both the DOM and Angular loading correctly, and timers and intervals. This is the third part on my series on Learn Javascript, the next will focus on NodeJS. Enjoy, share, fork and comments are always welcome.

The default configuration of the simulation is interesting – try a simulation of the form ‘left, left, right, right’ for another type of behaviour.


A great read for JavaScript newcomers

A superb article by Colin Eberhardt has just been published on the CodeProject, called ‘Understanding JavaScript Object Creation Patterns’.

This article should be on the reading list of anyone who’s new to JavaScript or not familiar with how objects and prototypes work. It takes you step by step through the basics all the way to protoypes and classes.

The article is at:


I’d strongly recommend it!


Space Invaders on the CodeProject

I’m currently writing a series of articles on the CodeProject called ‘Learn JavaScript’ and am pleased to say that the latest article is available now!

Learn JavaScript Part 2 – Space Invaders

In this article we take a look at how to create the classic space invaders game with plain JavaScript and HTML – no libraries or frameworks. You can see it in action on the page experiments/spaceinvaders. Check it out – as always, comments are welcome!



SharpShell 2.0

I have just released SharpShell 2.0  - you can get the release from sharpshell.codeplex.com or the new GitHub page at github.com/dwmkerr/sharpshell.

This release has been primarily a bugfixing release, but there is one very useful new feature, the Server Registration Manager tool (srm.exe). This is a standalone application that can be used to install and uninstall SharpShell servers.

srm install server.dll -codebase

srm uninstall server.dll

This tool makes it much easier to deploy SharpShell servers. You can call the tool as a Custom Action in a MSI project, either by using Visual Studio 2010′s installer project type, or a WiX project. I’ll be writing up an article on the CodeProject on how to use the tool soon, until then you can download the tool and try it out now!


ConsoleControl and Happy Coders

Sometimes I write up an article and some code on the CodeProject and get a good response, other times it seems an article sinks beneath the waves without any notice. Looking over some emails the other day, I noticed that my ConsoleControl article had actually received a slow and steady response of extremely positive feedback – people are using it and suggesting improvements.


This is great, it’s one of the things I love about the community of developers that I’m part of. So I decided to try and put a bit more back with ConsoleControl. I’ve moved the source code to GitHub, so that anyone can fork it and work on it easily:


I’ve bulked out the readme.md file with some more information and am working in the documentation. I’ve also added ConsoleControl to Nuget – you can install it for WinForms or WPF with the commands below:

PM> Install-Package ConsoleControl

PM> Install-Package ConsoleControl.WPF

Finally, I’m blogging about it here. It’s great to see people using a project like this, it’s rare for me to share comments like the ones below, but I must say I was touched by:

This is just about borderline genius. - Gerben Rampaart
Brilliant. So easy to use and works flawlessly. - Sukar
I saw similar controls – but yours is outstanding – I love it! BTW: Very nice coding (style, comments) – 5ed! - johannesnestler

To finish off this post, I’d like to say thanks to everyone who’s commented, suggested improvements and shared their experiences with the code, it’s a great feeling when you share something and it seems that people benefit from it. If you’ve used the code and want to share ideas for improvements or feedback, email, comment or hit the GitHub page or CodeProject article.


Space Invaders in JavaScript

If you take a look at the Experiments Page you’ll see that there’s a new entry – Space Invaders.


Space Invaders is a great little game to code if you’re learning a new language or technology (and JavaScript is still very much in that category for me). I’ll be writing up how I made the game on the CodeProject soon enough (if you’re interested you can see how I made the starfield background in JavaScript).

You can check back periodically – the game is nearly done and more than ready to play with. The code is available as well, either just get it from the browser or check Space Invaders on GitHub. I’ll post when it’s done and the next experiment starts!


Introducing Experiments

I’m staring a series of articles on learning Javascript (the first is available at http://www.codeproject.com/Articles/642499/Learn-JavaScript-Part-1-Create-a-Starfield). To help with this, I’ve created the Experiments page. This page will host each of the things I’ve been playing with in the process of learning JavaScript and coming up with good topics for tutorials.

You can see the Experiments page here, there’s also a link at the top of the site. If you like it, please feel free to comment on this post or get in touch.


Node.js and Express – Strange Http Status Codes

In a Nutshell

Sending a response in Express with a call like res.send(status, body) will send body as the status code if it is numeric – ignoring status. This is due to a fudge for backwards compatibility.

The Details

As part of a project I’m working on, I’m writing a service using node.js and Express. This service exposes some entities in a MongoDB database through a REST API. Typically I hit this API through client-side Javascript, but in some places I want to hit the same API from some C# code – and I don’t want to have to create classes for everything. I’ve got a funky library for this which I’ll be publishing soon, but it helped me find a problem.

Testing the C# code showed me something that was a bit odd – GETs and POSTSs were working fine, but PUTs and DELETEs were showing an HTTP Status code of ’1′ (which isn’t a valid code). Here’s the what I was seeing:


Checking the node server showed the same thing – DELETEs were returning status 1.


The server code is very lightweight so it’s quick to see what’s going on:

exports.deleteUser = function(request, response) {

	//	Get the id.
    var id = request.params.id;

    //	Log the user id.
    console.log('Deleting user: ' + id);

    //	Get the users collection, delete the object.
    db.collection(collectionName, function(err, collection) {
        collection.remove({'_id':new BSON.ObjectID(id)}, {safe:true}, function(err, result) {
            if (err) {
                console.log('Error deleting user: ' + err);
                response.send(400, {'error':'An error has occurred'});
            } else {
                console.log('' + result + ' document(s) deleted');

The function is called successfully, so we hit ‘response.send’. This looks like the problem – the result object is simply the number one, checking the Express Api Documentation for send shows some examples like this:

res.send(new Buffer('whoop'));
res.send({ some: 'json' });
res.send('some html');
res.send(404, 'Sorry, we cannot find that!');
res.send(500, { error: 'something blew up' });

So just like the final example, we’re sending the code 1, which is not valid. What surprised me was what happened when I changed the send call to the below:

response.send(200, result)

I was still getting the code 1 returned. It turns out that this is a kind of undocumented oddity of Express – if you pass a numeric code and the second argument is also numeric it sends the second argument as the status.

In response.js of Express we find:

res.send = function(body){
  var req = this.req;
  var head = 'HEAD' == req.method;
  var len;

  // allow status / body
  if (2 == arguments.length) {
    // res.send(body, status) backwards compat
    if ('number' != typeof body && 'number' == typeof arguments[1]) {
      this.statusCode = arguments[1];
    } else {
      this.statusCode = body;
      body = arguments[1];

So it seems the Express used to support a call like res.send({body}, 200) – and checks for a numeric second argument for backwards compatibility.

The workaround – don’t send numbers as any part of the response, unless it’s most definitely the status code – if you want to return the number of documents deleted, format it as json first, otherwise Express will get confused and mess with your status codes.