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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/108900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:15:56  来源:igfitidea点击:

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

windowssvnmfcversioninfo

提问by swilc0x

How do I go about programmatically updating the FILEVERSION string in an MFC app? I have a build process that I use to generate a header file which contains the SVN rev for a given release. I'm using SvnRev from http://www.compuphase.com/svnrev.htmto update a header file which I use to set the caption bar of my MFC app. Now I want to use this #define for my FILEVERION info.

如何以编程方式更新 MFC 应用程序中的 FILEVERSION 字符串?我有一个构建过程,用于生成一个头文件,其中包含给定版本的 SVN rev。我正在使用来自http://www.compuphase.com/svnrev.htm 的SvnRev来更新我用来设置 MFC 应用程序标题栏的头文件。现在我想将此#define 用于我的 FILEVERION 信息。

What's the best way to proceed?

最好的方法是什么?

回答by cjm

An .rcfile can #includeheader files just like .cfiles can. I have an auto-generated version.hfile, which defines things like:

一个.rc文件可以#include头文件一样.c的文件即可。我有一个自动生成的version.h文件,它定义了以下内容:

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

Then I just have my .rcfile #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 "
#define SVN_VERSION_NO  xxx
" VALUE "ProductVersion", MY_PRODUCT_VERSION "
#define SVN_VERSION_NO  xxx
" ...

I haven't tried this technique with an MFC project. It might be necessary to move your VS_VERSION_INFOresource to your .rc2file (which won't get edited by Visual Studio).

我还没有在 MFC 项目中尝试过这种技术。可能需要将您的VS_VERSION_INFO资源移动到您的.rc2文件(Visual Studio 不会对其进行编辑)。

回答by Dan

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. In our situation, our SVN revision was already above this and resulted in an invalid revision number in our FILEVERSION.

还没有足够的点数来评论,但无论您选择哪种解决方案,请记住 FILEVERSION 字段只能支持短整数。在我们的情况下,我们的 SVN 修订版已经高于此,并导致我们的 FILEVERSION 中的修订号无效。

回答by Aaron Fischer

In your application.rc file there is a version block. This block controls the version info displayed in the filesystem.

在您的 application.rc 文件中有一个版本块。此块控制文件系统中显示的版本信息。

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

VS_VERSION_INFO VERSIONINFO
FILEVERSION 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.

您可以以编程方式更新此文件。确保打开文件并将其保存为二进制文件。我们遇到了编辑作为文本完成并且文件损坏的问题。

回答by prakash

Changing VS_VERSION_INFOwill 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 文件
##代码##
##代码##
  • Your project includes this version.h and uses that number to show in caption.
  • 您的项目包含此 version.h 并使用该数字显示在标题中。

回答by mem64k

Maybe this can be helpful: Versioning Controlled Build

也许这会有所帮助:版本控制构建