Set DNX_BUILD_VERSION in the VSTS build

In a project where we use ASP.NET 5 (or ASP.NET Core 1.0) we wanted to use dynamic versioning in the build.

As described here you can use the asterisk (*) for the version in the project.json file

image

If you set the environment variable DNX_BUILD_VERSION to a value, the asterisk will be replaced with this value.

All fine, but when you run this on the build server it seems that the asterisk will only be replaced on the first run but the second and following build the new value of the environment variable is ignored.

To overcome this problem, I have created a simple powershell script, that replaces tha asterisk with a value of choice.

The powershell parses the project.json and replaces the asterisk with a buildname-buildversion (this can be anything). The script can be found here on Github. An example project.json is there as well.

You can run the powershell on the command line by running

.\Set-BuildVersion.ps1 -filePath .\project.json –buildName buildName -buildNumber 20160101

You can then add this powershell as a build task in your pipeline

 

image

Hope this helps !

Download source from github

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: