如何使用nant任务增加构建版本?更具体地说,我如何将它与assemblyinfo.cs中的版本号相关联?
答案 0 :(得分:8)
您需要考虑某种系统来管理版本增量。一种常见的方法是通过持续集成,例如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>
其中CCNetLabel是一个动态属性,它在执行nant时从CruiseControl设置。
答案 1 :(得分:3)
NAnt的<asminfo>
task可以帮助您生成AssemblyInfo.cs。
答案 2 :(得分:3)
我们使用TeamCity为NAnt提供版本号。然后将版本号注入到AssemblyInfo中,如下所示:
<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文件,该文件需要链接到解决方案中的所有项目。
答案 3 :(得分:2)
我正在使用多个引用项目(Windows窗体,类库和BatchConsole)
最好的例子是从nAnt Build文件中复制“Assemblyinfo”部分(你可以从Github下载)
诀窍是你可以使用你的nAnt Targets将引用它的commonAssemblyinfo文件。
来自nAnt文件的目标
<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>