Automate Windows Developer Machine Setup
With any serious software project you’ll quickly realize developer machine setup is non trivial. What I’ve experienced on projects in the past is someone decides to document the process (Yay!) but the documentation is quickly forgotten and is out of date by the time someone goes to use it (Boo!). Even in the best case where the documentation is up to date the process of downloading and installing required software manually is tedious, boring and error prone. Finishing your machine setup in a day or two was considered an accomplishment. Another popular option is maintaining a developer machine system image. We attempted this as well but if developers had different hardware it fell apart. Additionally the system image tended to get out of date just like the documentation.
As painful as those options were, they were pretty much the only options until Chocolatey came along. Chocolatey is a package manager for windows, much like apt-get for Linux or homebrew for OSX. Chocolatey is built on powershell and provides a command line interface to install programs. For example, installing Node JS is as simple as running
cinst nodejs.install. Additionally, Chocolatey can automate enabling windows features, ruby gems or python packages. To enable ASP.Net 4.5 on Windows 8, run
chocolatey WindowsFeatures IIS-ASPNET45.
Most installations are as simple as running a one line
cinst command. However, if you wish to customize an installation you can, assuming the installer supports it. For example, the Visual Studio 2012 package by default does not include the full installation to avoid a system restart on some machines. However, this is configurable via the
/AdminFile install argument. This optional argument should contain the path to an
admindeployment.xml file. The specification for this file is not very well documented by Microsoft, but if you just wish to install the full Visual Studio 2012, this gist will do just that. The full command to install Visual Studio 2012 in its entirety is
The commands above check to see if Visual Studio is installed. If not, the AdminDeployment.xml file is downloaded to the root of the C:\ drive and then Visual Studio is installed using its settings instead of the Chocolatey defaults.
Putting it all together
To get Chocolatey installed inside a batch script, run
This will ensure that Chocolatey is installed and add it to your PATH permanently (
SETX) and for the current session (
SET). You can then use any of the chocolatey commands like
cinst to setup the environment.
One thing I do stress is to make your setup script repeatable so that it can be run multiple times without harmful effects on the machine. For example if I needed to make sure git was installed I would run something like
This will only install git if it is not already installed, but Chocolatey would do that for us as well. The important thing this snippet does is not re-add git to the PATH, which is unnecessary and potentially harmful.
One other thing I would recommend is using the setup script to share out environment changes to the rest of the team. When a new requirement is added to the project, add it to the setup script and let everyone know they need to rerun the script. This will help ensure the script is always up to date, and can be run any number of times without affecting the environment.
With the addition of Chocolatey we have the power to script a full machine setup on Windows. Projects that I work on now have a predictable
machinesetup.bat script that a developer can run on a bare-bones machine to get up and running automatically in an hour or so. This is a huge improvement over what was previously a multi-day, error prone process.