Auto versioning SharePoint Apps (and Sandbox Solutions)

TL; DR;

spav  is a simple tool which can be used to automatically version SharePoint App packages and SandBox solution packages. You can provide custom app versioning library to provide your own mechanism to build app or WSP. It also can be used to generate application version JavaScript file which can later used to inject into pages and use in client side.

https://github.com/SachiraChin/SharePointAppAutoVersioning#examples

This a project which I created to automate the versioning of SharePoint hosted app. Initially it started as small tool, but in order to make it usable to other developers, I have added few modifications to it.

First I will explain the reason I created this tool in the first place. Recently I was involved in development of SharePoint app which had rapid development cycle. Client was expecting fast builds which deployed in SharePoint Online site. Client used his app catalog to publish the developed application across multiple sites. First version of the application published in multiple sites without any issue, but when we had to release next version of the app, we faced few problems.

  1. Versioning of the app package
  2. Update exiting content published by app -> Solution feature versioning

In order to update an application which published via app catalog, next version must have version upgrade. It can be major, minor or even patch level update, whichever it is, it must be reflected on Version property in AppManifest.xml file. If we do not change version in this file, site collection administrators will not see an app update in Site Contents.

Even if we update app version in AppManifest.xml file, it will not update the content we added in the app if we do not version application features properly. You can read more about versioning features in this blog post. As you can see, update content of the an app not easy as we think, and it all depends on feature version.

In this version of the application, my target was very simple. I wanted to maintain same version throughout the application as well as all features. In this way, when I add or update a file in a module, it’ll automatically get replaced.

Introduction

spav  is a simple tool which can be used to automatically version SharePoint App packages and SandBox solution packages. It also can be used to generate application version JavaScript file which can later used to inject into pages and use in client side.

Usage

In order to use this tool inside Visual Studio, you have to add pre or post deployment step to SharePoint add-in project. Whether to use pre-deployement or post-deployment is up to your requirement.

-p, --path  [Required] Directory of application project. Can be taken from $(ProjectDir) MSBUILD parameter.

-m, --mode  [Required] Running mode.

  • AppPackage: Increases the version of application package(.app)
  • Wsp: Build a sandbox compatible package with feature versioning
  • AppPackageAndWsp: Update app package and create sandbox solution

-b, --build-config  (Default: Debug) Application build configuration. Can be taken from $(Configuration) MSBUILD paramater.

-j, --build-js  (Default: False) Build JavaScript file to use in versioning for client side versioning. This will work with parameters –js-path and –js-class.

--js-path  (Default: {Path}\applicationVersion.js) Save path for JavaScript file.

--js-class  (Default: appVersion) JavaScript namespace to contain application version.

--versioning-lib  (Default: AutoIncrementBuildVersion.dll) Library used to get build version.

--versioning-class  (Default: SharePointAppAutoVersioning.AutoIncrementBuildVersion.VersionProvider) Full path of class in versioning library.

--help  Display help screen.

Examples

Auto increment patch and build version of the SharePoint App package

Generate SandBox compatible solution with feature updates

Update app package version and generate SandBox solution

Build JavaScript file which can be used inside the application while updating version of app package

This will generate below JS file.

NOTE: Application will use 5 commented lines which is on top of JavaScript file to generate the next version. If you erase these lines, version will be resetted to 1.0.0.0. If you want to change major or minor version, you can change it in here and it’ll be reflected it next build.

You can access version values as below,

Use custom versioning library

You can write your own custom versioning library for your versioning purposes. In order to do that, you have to create new class library and add reference to SharePointAppAutoVersioning.Shared.dll  file which you can find in application folder.

Lets assume that dll from your project is ContosoApp.CustomBuildVersion.dll . In order to use this inside the application, you have to copy this file to location of spav.exe  path. After you copy it, you can use it like below.

I will explain in another post about tools and libraries which I used to develop this application. Meanwhile, you can check my repo here, fork it, do your customization and send pull request to me. I’d like to add new versioning libraries for different scenarios and make it usable for more people. 🙂 Happy coding!!

Leave a Reply

Your email address will not be published. Required fields are marked *