下面是我的 NANT 脚本片段,它从我的一个 C# 项目中读取 Assemblyversion 并自动增加它。
<target name="CheckAssembly">
<echo message="Check Assembly File version..." />
<property name="file.contents" value="" />
<loadfile property="file.contents" file="${properties.path}\AssemblyInfo.cs" />
<regex pattern="(AssemblyVersionAttribute|AssemblyVersion)\(\x22(?'major'\d+).(?'minor'\d+).(?'build'\d+).(?'revision'\d+)\x22\)" input="${file.contents}" />
<property name="application.AssemblyInfo.dir" value="${properties.path}" />
<property name="AssemblyVersion" value="${major}.${minor}.${build}.${int::parse(revision)}" />
<if test="${int::parse(updates.count)>1}">
<property name="AssemblyVersion" value="${major}.${minor}.${build}.${int::parse(revision) +1}" />
<call target="UpdateAssembly" />
</if>
</target>
<target name="UpdateAssembly" description="generates the version number">
<echo message="Setting the build version to ${AssemblyVersion}..." />
<attrib file="${application.AssemblyInfo.dir}\AssemblyInfo.cs" readonly="false" />
<asminfo output="${application.AssemblyInfo.dir}\AssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System.Runtime.CompilerServices" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="AssemblyTitleAttribute" value="${appName}" />
<attribute type="AssemblyDescriptionAttribute" value="" />
<attribute type="AssemblyConfigurationAttribute" value="" />
<attribute type="AssemblyCompanyAttribute" value="Company Name" />
<attribute type="AssemblyProductAttribute" value="" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright © 2010-2013" />
<attribute type="AssemblyTrademarkAttribute" value="" />
<attribute type="AssemblyCultureAttribute" value="" />
<attribute type="AssemblyVersionAttribute" value="${AssemblyVersion}" />
<attribute type="AssemblyFileVersionAttribute" value="${AssemblyVersion}" />
</attributes>
</asminfo>
<attrib file="${application.AssemblyInfo.dir}\AssemblyInfo.cs" readonly="true" />
</target>
现在我正面临下一个挑战。我有一个 C++ 项目,使用 NANT 可以很好地编译,但我想更新与您在上面看到的类似的程序集版本。在这个 C++ 项目中,我的 ProductVersion 保存在资源文件 (.rc) 中。
你知道 NANT 是否有任何有助于改变这一点的功能/标签?如果没有,您对我应该如何处理这个有任何想法吗?我已经考虑过读取文件内容并使用正则表达式来做到这一点。