vswhere now supports -utf8 to override console code page

Heath Stewart

A new switch parameter has been introduced to vswhere. You can now pass -utf8 to force output to write text using UTF-8 to the console, though it’s important to note that what the console host does with that encoded can vary greatly. powershell.exe, for example, when redirecting to a file will always encode Unicode regardless of the [Console]::OutputEncoding or program output encoding.

The problem is that while Visual Studio 2017 instance data is stored as UTF-8 and the query API parses this text into Unicode strings in memory, vswhere writes these strings using the console APIs which transcode text based on the active code page or text written to a file or to a pipe is incorrectly transcoded into gibberish…or at least a bunch of question marks (fallback character). After much discussion, to avoid breaking changes the new switch parameter -utf8 was added to force text to use UTF-8 expecting that the caller will handle it appropriately as in the following example.

const cp = require('child_process');
cp.execFile('vswhere.exe', ['-latest', '-format', 'json', '-utf8'], (err, stdout, stderr) => {
  var instances = JSON.parse(stdout);
  if (instances.length > 0) {
    // do something with instances[0].description

Install vswhere and give it a try.


Discussion is closed.

Feedback usabilla icon