Chocolatey

I played with Chocolatey today, I figured lets create an package to setup a development machine. Add handy packages that you might want starting out on a new machine. This is handy as well when you have a new developer joining your team, you can set them up with some common tools.

First create the spec file as below

<?xml version=“1.0”?>
<package>
  <metadata>
    <id>SoftwareCreations.devset</id>
    <title>SoftwareCreations.devset</title>
    <version>0.09</version>
    <authors>Orn Kristjansson</authors>
    <summary>Software Creations, installs dev tools.</summary>
    <owners>Orn Kristjansson</owners>
    <description>Installs handy development tools.</description>
    <projectUrl>https://github.com/ornatwork/</projectUrl>
    <tags>SoftwareCreations devset tools development</tags>
    <copyright>Software Creations</copyright>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <iconUrl>http://kristjansson.us/favicon.ico</iconUrl>
    <dependencies>
      <dependency id=“fiddler” />
      <dependency id=“filezilla” />
      <dependency id=“winrar” />
      <dependency id=“sublime” />
      <dependency id=“gimp” />
      <dependency id=“dotpeek” />
      <dependency id=“grepwin” />
      <dependency id=“skype” />
      <dependency id=“testdriven.net” />
      <dependency id=“MagicDisc” />
      <dependency id=“winmerge” />
      <dependency id=“tortoisesvn” />
      <dependency id=“TortoiseGit” />
      <dependency id=“windowstelnet” />
    </dependencies>
    <releaseNotes>
    </releaseNotes>
  </metadata>
  <files>
    <file src=“tools\**” target=“tools” />
    <file src=“content\**” target=“content” />
  </files>
</package>

For this spec I have only dependencies which means I’m not really installing anything myself. Rather pulling and installing the dependencies. As such there is a /tool directory that has a PowerScript file that doesn’t do anything. Secondly since some of these packages have /content directory that needs to be created as well. If not an error will be thrown when the package is run ( that’s a bug ). There for I just put fake.txt file in that directory that is enough to get around the error.

My source can be found on GitHub

Since I don’t like doing tasks by hand that can be automated I created a nant script to create the package and push it up on the Chocolatey server. When I make a change to the package I save it and then on the command line just run the nant script.

For example
> nant -D:version=0.10

<?xml version=“1.0”?>

<!– Chocolatey fun –>
<project name = “SofwareCreateions.devset”
                 default = “PackAndDeploy”
                 basedir=“.”>

  <!–  Register the sys.* properties; most specifically, sys.env.* for all environment vars   –>
  <sysinfo failonerror=“false” />

  <!– The version number for the package –>
  <property name=“version” value=“0.01” dynamic=“true” overwrite=“true” />
  <property name=“BuildDrive” value=“${string::substring(project::get-base-directory(), 0, 1)}”  dynamic=“true” />
  <property name=“path.base.drive” value=“${BuildDrive}:\” />
  <property name=”cmdChocolateyPath” value=”${path.base.drive}\Chocolatey\bin\” />
  <property name=”cmdChocolatey” value=”chocolatey.bat” />
  <property name=”nugetFile” value=”softwarecreations.devset” />

  <!– This is the main / default target –>
  <target name=”PackAndDeploy” depends=”Start, UpdateVersion, Package, Deploy“>
    <echo message=”Done !“/>
  </target>

  <!– Individual targets below, those should NOT have any dependancies –>
  <target name=”Start” >
    <echo message=”*** Version number=${version} “/>

  </target>

  <!– Update version number –>
  <target name=”UpdateVersion” description=”Update version files to the current version being built.”  >
   
    <echo message=”*** Start updateVersions: ver=${version}“/>
   
    <!– Update NuGet package version –>
    <xmlpoke file=”softwarecreations.devset.nuspec” xpath=”/package/metadata/version” value=”${version}” />

  </target>

  <!– Package –>
  <target name=”Package“>
    <echo message=”Start Package:“/>

    <echo message=”Push to Nuget feed:“/>
    <!– Deploy to Nuget Gallery –>
    <exec program=”${cmdChocolateyPath}${cmdChocolatey}” verbose=”true
          commandline=”
pack ${nugetFile}.nuspec“/>
   
  </target>

  <!– Deploy –>
  <target name=”Deploy“>
    <echo message=”Start Deploy:“/>
   
    <exec program=”${cmdChocolateyPath}${cmdChocolatey}” verbose=”true
          commandline=”
push ${nugetFile}.${version}.nupkg“/>
   
  </target>

</project>

My package and it’s content can be found here If your have Chocolatey installed you can run it from the command line, like so.

> cinst SoftwareCreations.devset

Chocolatey is like apt-get on the Linux box, when you start using it its hard to go back to the manual search – webpage – download – install routine. There are only about 1200+ packages available at this point but that will grow going forward for sure.

2 Comments

  1. Grey Ham says:

    Hello!

    Great post… and very timely given we use Chocolatey in a similar way to get our VM’s up and running in a consistent fashion.

    Like you, we use Chocolatey for describing how we want our virtual machines set up for various scenarios (debugging/troubleshooting, browser testing etc). We want all developers to use the same package sequences. To aid with standardization, we use a Visual Studio Tool – MarraLAB (BLATANT PLUG WARNING: I wrote it :-)) – to allow other developers on the same project to discover those packages and to drag ‘n’ drop then onto their running virtual machines to start the installs. You can read the whole integration post with MarraLAB here: http://www.havecomputerwillcode.com/blog/?p=1090

    MarraLAB is free and can be downloaded here: http://visualstudiogallery.msdn.microsoft.com/3361e80e-1200-4891-939b-b9203d55c5d8?SRC=Home

    Currently, Chocolatey is just another integration with MarraLAB but I am very keen on making it a first class citizen and tightly integrating with it: if you’ve any ideas on how you would like to see this working, feel free to get in touch via my blog or Linked In.

    Cheers!

    Grey Ham

  2. orn says:

    Nice, I will take a closer look at MaraLAB when I have some time. Looks like you have a great tool there.

    Orn

Leave a Reply