如何使用nant任务来增加构建版本?更具体地说,我怎样将此与assemblyinfo.cs中的版本号相关联?
你需要考虑一些版本增量管理的系统。其中一种常见的方式是通过持续集成进行,例如像CruiseControl.NET。如果您选择这种方法,可以使用如下的构建目标:
<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>
<asminfo output="${solutionDir}/CommonAssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${version}" />
</attributes>
</asminfo>
这将创建一个CommonAssemblyInfo.cs文件,其中包含指定的版本号,需要将其链接到解决方案中的所有项目。
<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>