简体   繁体   English

以编程方式更新具有SVN修订号的MFC应用程序中的FILEVERSION

[英]Programmatically updating FILEVERSION in a MFC app w/SVN revision number

How do I go about programmatically updating the FILEVERSION string in an MFC app? 如何以编程方式更新MFC应用程序中的FILEVERSION字符串? I have a build process that I use to generate a header file which contains the SVN rev for a given release. 我有一个构建过程,我用它来生成一个头文件,其中包含给定版本的SVN rev。 I'm using SvnRev from http://www.compuphase.com/svnrev.htm to update a header file which I use to set the caption bar of my MFC app. 我正在使用来自http://www.compuphase.com/svnrev.htm的 SvnRev来更新我用来设置我的MFC应用程序的标题栏的头文件。 Now I want to use this #define for my FILEVERION info. 现在我想将这个#define用于我的FILEVERION信息。

What's the best way to proceed? 什么是最好的方法?

An .rc file can #include header files just like .c files can. .rc文件可以#include头文件,就像.c文件一样。 I have an auto-generated version.h file, which defines things like: 我有一个自动生成的version.h文件,它定义了以下内容:

#define MY_PRODUCT_VERSION    "0.47"
#define MY_PRODUCT_VERSION_NUM 0,47,0,0

Then I just have my .rc file #include "version.h" and use those defines. 然后我只有我的.rc文件#include "version.h"并使用这些定义。

VS_VERSION_INFO VERSIONINFO
 FILEVERSION MY_PRODUCT_VERSION_NUM
 PRODUCTVERSION MY_PRODUCT_VERSION_NUM
...
 VALUE "FileVersion", MY_PRODUCT_VERSION "\0"
 VALUE "ProductVersion", MY_PRODUCT_VERSION "\0"
...

I haven't tried this technique with an MFC project. 我没有尝试过MFC项目的这种技术。 It might be necessary to move your VS_VERSION_INFO resource to your .rc2 file (which won't get edited by Visual Studio). 可能需要将VS_VERSION_INFO资源移动到.rc2文件(不会被Visual Studio编辑)。

Don't have enough points to comment yet, but whatever solution you choose keep in mind that FILEVERSION fields can only support a short integer. 没有足够的评论点,但无论你选择哪种解决方案,请记住FILEVERSION字段只能支持一个短整数。 In our situation, our SVN revision was already above this and resulted in an invalid revision number in our FILEVERSION. 在我们的情况下,我们的SVN修订已经高于此,并导致我们的FILEVERSION中的修订号无效。

In your application.rc file there is a version block. 在您的application.rc文件中有一个版本块。 This block controls the version info displayed in the filesystem. 此块控制文件系统中显示的版本信息。

VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1 FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1

You can programmatically update this file. 您可以通过编程方式更新此文件。 Make sure to open and save the file as binary. 确保打开并将文件另存为二进制文件。 We have had issues where edits are done as text and the file gets corrupted. 我们遇到过以文本形式进行编辑并且文件损坏的问题。

Changing VS_VERSION_INFO will reflect when you right click on the file in Explorer and see properties only. 当您在资源管理器中右键单击该文件并仅查看属性时,更改VS_VERSION_INFO将反映出来。

If you want to show the current SVN revision number in the Caption bar, i would suggest: 如果要在标题栏中显示当前的SVN修订号,我建议:

  • Have a script get the version number and generate version.h file just with 让脚本获取版本号并生成version.h文件
 #define SVN_VERSION_NO xxx 
  • Your project includes this version.h and uses that number to show in caption. 您的项目包含此version.h并使用该编号显示在标题中。

也许这会有所帮助: Versioning Controlled Build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM