Creating and releasing Umbraco packages for multiple platforms using Grunt

by Anders Bjerner

Creating and releasing Umbraco packages for multiple platforms using Grunt

If you ever tried creating a package for Umbraco, there might be quite a few steps involved when pushing a new release, taking up time you could use for development instead.

When I create packages for Umbraco, I usually release my package via three different platforms: a NuGet package to be installed via Visual Studio, a ZIP file of the relevant files uploaded to GitHub, and an actual Umbraco package uploaded to Our Umbraco. Targeting three different platforms then obviously involves even more steps.

So can we do something to automate this? YES!

The power of Grunt

There are multiple ways of obtaining the same result - eg. some build servers supports creating a NuGet package for each build.

But since we at Skybrud.dk already are using Grunt for our frontend stuff, I've opted for using Grunt for this as well.

Getting startedFor creating a release for each platform, we'll need some information about our package. We can declare this in Gruntfile.js, but to keep things a bit separate, I've gone with appending this to package.json instead.

Since the the release for each platform will be based on a Visual Studio project, it would make sense to get as much information from the DLL of that project. Since I haven't found a way to do this directly using either npm or Grunt, I have created a small tool called UpdateAssemblyInfoJson that generates a JSON file with information about the DLL.

The .csproj file of our Grid project is located at /src/Skybrud.Umbraco.GridData/Skybrud.Umbraco.GridData.csproj. To generate the mentioned JSON file, I've added a post build event to the Visual Studio project:

Determining relevant files for the packagesFor the GitHub ZIP file and the Umbraco ZIP package, I setup /files as the source directory, and copy relevant files here using the grunt-contrib-copy task. To make sure the directory is empty before copying, I'm also using the grunt-contrib-clean task.

NuGetFor creating the NuGet package, I'm using the grunt-nuget package. It adds tasks for a number of purposes, but most importantly the nugetpack task.

The task is then based on /src/Skybrud.Umbraco.GridData/Skybrud.Umbraco.GridData.csproj. When the pack task is based on a .csproj file, NuGet will automatically look for a .nuspec file with the same basename. So in this example, NuGet will find /src/Skybrud.Umbraco.GridData/Skybrud.Umbraco.GridData.nuspec, which looks like:

When setting up the task with the configuration shown below, the task will automatically generate the manifest, and add the files that we earlier copied to /files. The ZIP archive is then saved to /releases/umbraco/Skybrud.Umbraco.GridData.v1.5.0.zip.