moodmosaic

Compiling .NET projects in Sublime Text

The subject of this post is the compilation of .NET projects and solutions in Sublime Text using the Build Systems feature.

Sublime Text supports custom Build Systems.

By adding MSBuild as a new Build System, it is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed.

Adding the Source Code

The following steps require a folder with MSBuild project files. In order to be pragmatic, the custom Build System is going to compile the source code of AutoFixture.

Go to the File menu, click Open Folder... and select the root folder of the project to be compiled.

Adding the new Build System

Go to the Tools menu, Build System, and click New Build System...

Paste the following code into a file:

{
    "cmd": ["C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe", "AutoFixture.sln"],
    "working_dir": "${project_path:${folder:${file_path}}}\\Src"
}

Save the file as AutoFixture.sublime-build.

Go to the Tools menu, Build System, and select AutoFixture.

The above steps are per MSBuild project file. Repeat the above steps by creating a Build System per MSBuild project file.

Running the Build

Go to the Tools menu, and select Build. Alternatively, use the Ctrl+B command.

The compiler detects a missing semicolon.

In the above screenshot, on line 38, a semicolon has been intentionally removed for the demo. After running a build, the compiler detects the missing semicolon.

What about the Tests?

Currently, the easiest way to run the tests is by using a command-line interface version of the test runner.

On my machine, attempting to add a new Build System for the tests resulted in high memory usage. This was tested while Sublime Text 3 was in beta (Build 3010).