下面是我的 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>
现在我正面临下一个挑战。我有一个使用 NANT 编译良好的 C++ 项目,但我想更新类似于您在上面看到的程序集版本。在这个 C++ 项目中,我将 ProductVersion 保存在资源文件 (.rc) 中。
你知道 NANT 是否有任何功能/标签可以帮助改变这个吗?如果没有,您知道我应该如何处理这个问题吗?我已经考虑过读取文件内容并使用正则表达式来执行此操作。
最佳答案
我知道这是一个非常古老的问题,但我今天一直在研究同样的问题。我使用 ANT 解决了这个问题(请原谅我的正则表达式:/)。我假设 Nant 将以与普通 ANT 非常相似的方式运行。
<echo message="Modifying VersionResource.rc" />
<replaceregexp byline="true" flags="g" encoding="UTF-16LE" >
<regexp pattern="[0-9]+,[0-9]+,[0-9]+,[0-9]+" />
<substitution expression="${adapter_resource}" />
<fileset dir="${my.dir}">
<include name="VersionResource.rc" />
</fileset>
</replaceregexp>
<echo message="Modifying VersionResource.rc again..." />
<replaceregexp byline="true" flags="g" encoding="UTF-16LE" >
<regexp pattern=""(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}"" />
<substitution expression=""${adapter_versions}"" />
<fileset dir="${my.dir}">
<include name="VersionResource.rc" />
</fileset>
</replaceregexp>
${adapter_versions} 在调用构建过程时在命令行上设置。
关于c++ - NANT 修改 C++ 项目的程序集版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761757/