Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Created December 11, 2015 00:57
Show Gist options
  • Save sdesalas/1f400af9fedd1a264dd2 to your computer and use it in GitHub Desktop.
Save sdesalas/1f400af9fedd1a264dd2 to your computer and use it in GitHub Desktop.
Uses NANT to check version info in AssemblyInfo.cs
<?xml version="1.0"?>
<project name="MyProject" default="test-all" basedir=".">
<description>
********************************************
nant.check-version.xml
********************************************
By: Steven de Salas
On: November 2015
This is a NAnt build script that checks the version.
For debugging open a command line prompt and type:
> cd (path to this project)
> nant.exe -buildfile:test\nant.check-version.xml
********************************************
</description>
<!-- 1. Define the variables (ie 'properties' in nant-speak) we will be using -->
<property name="build.configfile.dir" value="${directory::get-current-directory()}\source\IIS\MyProject\Bin" />
<!-- 2. Check the version -->
<target name="test-all">
<fail unless="${property::exists('build.version')}">
******************
CHECK FAILED!
******************
Please set the build.version variable in your command line as follows:
> nant.exe -buildfile:test\nant.check-version.xml -D:build.version=2.2.1
Thanks!
</fail>
<property name="build.configfile.path" value="${build.configfile.dir}\MyProject.dll" />
<call target="test-file" />
<!-- all ok? -->
<call target="success" />
</target>
<target name="test-file">
<echo message="Checking file '${build.configfile.path}'..." />
<property name="assembly.version" value="${assemblyname::get-version(assemblyname::get-assembly-name(property::get-value('build.configfile.path')))}" />
<if test="${property::get-value('assembly.version')!=property::get-value('build.version')}">
<fail message="
******************
INCORRECT VERSION
******************
You are using: '${assembly.version}'
The project is at: '${build.version}'
******************
Did you remember to update the AssemblyInfo.cs version?" />
</if>
</target>
<target name="success">
<echo message="
******************
CORRECT VERSION
******************
Version number set correctly to '${build.version}'
" />
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment