Nant <version> task
You want to consider some kind of system for managing your changes in the version. One common way to do this is through continuous integration, such as CruiseControl.NET . If you go this route, you can use the build target as follows:
<target name="set.version" description="generates the version number"> <echo message="Setting the build version to ${CCNetLabel}..." /> <attrib file="AssemblyInfo.cs" readonly="false" /> <asminfo output="AssemblyInfo.cs" language="CSharp"> <imports> <import namespace="System" /> <import namespace="System.Reflection" /> </imports> <attributes> <attribute type="AssemblyVersionAttribute" value="${CCNetLabel}" /> <attribute type="AssemblyFileVersionAttribute" value="${CCNetLabel}" /> </attributes> </asminfo> <attrib file="AssemblyInfo.cs" readonly="true" /> </target> Where CCNetLabel is a dynamic property that is set from CruiseControl when nant is executed.
We use TeamCity to supply NAnt with version number. Then the version number is entered into AssemblyInfo as follows:
<asminfo output="${solutionDir}/CommonAssemblyInfo.cs" language="CSharp"> <imports> <import namespace="System" /> <import namespace="System.Reflection" /> </imports> <attributes> <attribute type="AssemblyVersionAttribute" value="${version}" /> </attributes> </asminfo> This creates a file CommonAssemblyInfo.cs with the specified version, which should be associated with all the projects in your solution.
I use several reference projects (Windows Forms, Class Library and BatchConsole)
The best example would be to copy the “Assemblyinfo section” from the nAnt assembly file (you can download it from Github )
The trick is that you can use the commonAssemblyinfo file to which your nAnt targets will be bound.
Below is the target from the nAnt file
<target name="create-common-assemblyinfo" if="${create.assemblyinfo}"> <!-- ensure src/CommonAssemblyInfo.cs is writable if it already exists --> <attrib file="src/CommonAssemblyInfo.cs" readonly="false" if="${file::exists('src/CommonAssemblyInfo.cs')}" /> <!-- generate the source file holding the common assembly-level attributes --> <asminfo output="src/CommonAssemblyInfo.cs" language="CSharp"> <imports> <import namespace="System" /> <import namespace="System.Reflection" /> <import namespace="System.Runtime.InteropServices" /> </imports> <attributes> <attribute type="ComVisibleAttribute" value="false" /> <attribute type="CLSCompliantAttribute" value="true" /> <attribute type="AssemblyTitleAttribute" value="NAnt" /> <attribute type="AssemblyDescriptionAttribute" value="A .NET Build Tool" /> <attribute type="AssemblyConfigurationAttribute" value="${project.release.type}" /> <attribute type="AssemblyCompanyAttribute" value="http://nant.sourceforge.net" /> <attribute type="AssemblyProductAttribute" value="NAnt" /> <attribute type="AssemblyCopyrightAttribute" value="Copyright (C) 2001-${datetime::get-year(datetime::now())} Gerry Shaw" /> <attribute type="AssemblyTrademarkAttribute" value="" /> <attribute type="AssemblyCultureAttribute" value="" /> <attribute type="AssemblyVersionAttribute" value="${project.version}.${build.number}.0" /> <attribute type="AssemblyInformationalVersionAttribute" value="${project.version}" /> </attributes> </asminfo> </target>