Blog

Sublime Text 3 Build Systems

Featuring integration with Visual Studio 2015

By Samuel Turner on April 10, 2016 at 10:50 PM AEST

Build Systems Preview

Sublime Text is my favourite text editor and recently I was wondering if I could bring my Visual Studio projects into it. How did it go? Keep on reading to find out!


First up - The End Result

Before I go into the details, here's the configuration that I ended up with. It should work for most Visual Studio Solutions.

Note: I'm using Visual Studio 2015

code (filetype .sublime_build)

  {
    "variants":
    [
      {
        "name": "Debug x64",
        "cmd": [
          "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe",
          "/t:build",
          "/p:Configuration=Debug",
          "/p:Platform=x64"
        ],
        "working_dir": "C:\\Code\\CryoStarEngine"
      },
      {
        "name": "Debug x86",
        "cmd": [
          "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe",
          "/t:build",
          "/p:Configuration=Debug",
          "/p:Platform=x86"
        ],
        "working_dir": "C:\\Code\\CryoStarEngine"
      },
      {
        "name": "Release x64",
        "cmd": [
          "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe",
          "/t:build",
          "/p:Configuration=Release",
          "/p:Platform=x64"
        ],
        "working_dir": "C:\\Code\\CryoStarEngine"
      },
      {
        "name": "Release x86",
        "cmd": [
          "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe",
          "/t:build",
          "/p:Configuration=Release",
          "/p:Platform=x86"
        ],
        "working_dir": "C:\\Code\\CryoStarEngine"
      }
    ] 
  }

So what do we have here, let's break it down:

  • variants

    A Variant lets you have multiple different builds at your disposal within the 1 build system. In my case I've used it to define a mirror of the build configurations that Visual Studio gives me access to.

  • Within each Variant

    • name

      The name that will show up in the variants list when you go to build

    • cmd

      The program that will be called when you go to do a build. I've split up the arguments to pass through into separate lines here which aids readability. I also found that with the arguments on the same line as the first line, Sublime couldn't parse it properly

    • working_dir

      The directory that your command will be run from. Visual Studio intelligently finds Solution files within the working directory so as long as you have one Solution file to work with, you should be good!

In more detail

Starting with Sublime Text's Unofficial Docs I built the simplest form of a build system. A command with a working directory.

code (filetype .sublime_build)

  {
    "cmd": [
      "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe"
    ],
    "working_dir": "C:\\Code\\CryoStarEngine"
  }

Notes:

  • If you have a different version of Visual Studio installed, you'll need to find where your MSBuild lives. If you're building a .NET project then you can go looking into the Windows\Microsoft.NET\Framework folder

  • There are a bunch of useful variables you can use to build your working directory. I went for a fixed path here to get things up and running as fast as possible.

From there I was able to start putting in variants and create my final configuration. Along the way I refreshed myself on MSBuild's command line switches, testing things in the command prompt before bringing them into the BuildSystem file. When testing, always find the fastest form of iteration!

The result

The first time you Build (either from the Tools menu or with Ctrl+B) you'll get a handy drop down of your Variants to choose from:

Build System Variants

Choose a Variant and watch the magic happen in the build window that appears at the bottom of the screen!

Build Window

Next time you Build, Sublime will choose the Variant that you last built with. To get the list of Variants once more, use "Build With..." from the Tools menu or press Ctrl+Shift+B

Wrap up

So while this won't keep me away from Visual Studio (it has too many nice tools for me to say no to it), being able to write and compile code without leaving my favourite text editor is very satisfying

Back to Blog