1

以下は、C# プロジェクトの 1 つから Assemblyversion を読み取り、それを自動的に増やす NANT スクリプトのスニペットです。

<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)&gt;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 がこれを変更するのに役立つ関数/タグを持っているかどうか知っていますか? そうでない場合、私がこれにどのようにアプローチすべきかについて何か考えがありますか? 私はすでにファイルの内容を読み取り、これを行うために正規表現を使用することを考えていました。

4

1 に答える 1

0

これは本当に古い質問であることは知っていますが、今日も同じ問題に取り組んでいます。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="&quot;(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}&quot;" />
    <substitution expression="&quot;${adapter_versions}&quot;" />
    <fileset dir="${my.dir}">
        <include name="VersionResource.rc" />
    </fileset>
</replaceregexp>

${adapter_versions} は、ビルド プロセスを呼び出すときにコマンド ラインで設定されます。

于 2013-12-23T04:30:12.103 に答える