使用SubWCRev实现VS编译exe自带版本号

  1. 先使用添加 - 资源 - 版本号,生成一个 项目名.rc 文件;
  2. 将这个文件备份,重命名为随便什么名字,例如 temp_svn.rc;
  3. 修改这个 rc 文件中的 FILEVERSION 和 PRODUCTVERSION,各有两处;
  4. 修改之前是 1.0.0.0,可以修改成你想要的样子,SVN自带的软件 SubWCRev 会修改这个文件中你填写的关键字;
  5. 关键字列表如下:
    关键字 描述
    $WCREV$ 用工作副本中最高的提交版本来替换
    $WCREV&$ 用工作副本中的最高提交修订版本号替换,ANDed with the value after the & char. 例如:$WCREV&0xFFFF$
    $WCREV-$, $WCREV+$ Replaced with the highest commit revision in the working copy, with the value after the + or - char added or subtracted. For example: $WCREV-1000$
    $WCDATE$, $WCDATEUTC$ Replaced with the commit date/time of the highest commit revision. By default, international format is used: yyyy-mm-dd hh:mm:ss. Alternatively, you can specify a custom format which will be used with strftime(), for example: $WCDATE=%a %b %d %I:%M:%S %p$. For a list of available formatting characters, look at the 在线引用.
    $WCNOW$, $WCNOWUTC$ Replaced with the current system date/time. This can be used to indicate the build time. Time formatting can be used as described for $WCDATE$.
    $WCRANGE$ Replaced with the update revision range in the working copy. If the working copy is in a consistent state, this will be a single revision. If the working copy contains mixed revisions, either due to being out of date, or due to a deliberate update-to-revision, then the range will be shown in the form 100:200.
    $WCMIXED$ 当有混合版本时用 TText 替换 $WCMIXED?TText:FText$,否则用 FText 替换。
    $WCMODS$ 若本地存在修改,就用 TText 替换 $WCMODS?TText:FText$,否则用 FText 替换。
    $WCUNVER$ $WCUNVER?TText:FText$ is replaced with TText if there are unversioned items in the working copy, or FText if not.
    $WCEXTALLFIXED$ $WCEXTALLFIXED?TText:FText$ is replaced with TText if all externals are fixed to an explicit revision, or FText if not.
    $WCISTAGGED$ $WCISTAGGED?TText:FText$ is replaced with TText if the repository URL contains the tags classification pattern, or FText if not.
    $WCURL$ 用传递给SubWCRev的工作目录的版本库地址替换。
    $WCINSVN$ $WCINSVN?TText:FText$ is replaced with TText if the entry is versioned, or FText if not.
    $WCNEEDSLOCK$ $WCNEEDSLOCK?TText:FText$ is replaced with TText if the entry has the svn:needs-lock property set, or FText if not.
    $WCISLOCKED$ $WCISLOCKED?TText:FText$ is replaced with TText if the entry is locked, or FText if not.
    $WCLOCKDATE$, $WCLOCKDATEUTC$ Replaced with the lock date. Time formatting can be used as described for $WCDATE$.
    $WCLOCKOWNER$ Replaced with the name of the lock owner.
    $WCLOCKCOMMENT$ Replaced with the comment of the lock.
    $WCUNVER$ $WCUNVER?TText:FText$ is replaced with TText if there are unversioned files or folders in the working copy, or FText if not.
  6. 例如要换成文件夹 SVN 版本号,改成 1.0.0.SVN版本号 这样,就填 1.0.0.$WCREV$,当然填日期也是不错的;
  7. 填的时候注意,在windows属性里面看版本号的时候,有一个文件版本号,好像每一位只支持到short,所以像年月日这样加起来可能超过short范围的最好别使用;
  8. 在VS要编译的项目上 右键 - 属性 - 生成事件 - 预生成事件 - 命令行 中填写 SubWCRev "../" "temp_svn.rc" "项目名.rc" -f 即可在编译时生成包含有版本号的exe了。

更官方,更权威的说明,在svn官网:https://tortoisesvn.net/docs/nightly/TortoiseSVN_zh_CN/tsvn-subwcrev.html

其中关于日期的使用可以参考这里:https://msdn.microsoft.com/en-us/library/fe06s4ak.aspx

你可能感兴趣的:(编程)