如何增加之后每 VisualC++ 中生成版本信息
来源:互联网 发布:c语言中括号的用法 编辑:程序博客网 时间:2024/06/05 01:52
转自MSDN :http://support.microsoft.com/kb/237870/zh-cn
创建新项目使用 MFC (EXE) Appwizard 并调用它 MyProject . MyProject 将有一个 MyProject.rc 文件, 包括 MyProject.rc2。 .rc 2 文件是用于用户定义资源。 请按照下列步骤来增加每生成后 MyProject 的版本信息: 1. Remove the version resource from the .rc file and place it in the .rc2 file:
a. Open both MyProject.rc and MyProject.rc2 (found in the Res folder), in a text editor. To use the Visual C++ editor, click Open on the File menu and select Text in the Open As list for the MyProject.rc file. b. Find the version resource statements in MyProject.rc. It should look something like:
Now, MyProject.rc file includes MyProject.rc2, and MyProject.rc2 file includes VersionNo.h. 5. The VersionNo.h file contents will be modified using a Visual Basic Script macro. The macro described below handles the Visual C++ BuildFinish event, so it will not be fired until a build completes. Whenever this VB Script code is called, it first increments the version numbers inside the header file by a fixed amount, then it saves the file and closes it. During a subsequent build, the new version number is included in the executable.
To install and use the VB Script code, do the following:
a. Open an existing DSM (macro) file or create a new DSM file in Visual C++. To create a new file, click New on the File menu, select Macro File on the Files tab, give it a name, and click OK. b. Paste the following VB Script code below (an empty DSM file cannot be installed in Visual C++; the next step explains installing):
概要
VisualC++ 不具备功能来自动增加版本资源信息项目的各个生成后。 本文介绍一个地提供这些功能。
回到顶端
更多信息
您可以编写程序来修改资源编译器 (.rc) 文件而不是使用这里介绍步骤。 但是, RC 文件是个 VisualC++ 控制下。 VisualC++ 修改同时保存, RC 文件并可能会影响版本资源。 本节中介绍方法可应用于任何 VisualC++ 项目。 本示例使用 Microsoft 基础类项目。创建新项目使用 MFC (EXE) Appwizard 并调用它 MyProject . MyProject 将有一个 MyProject.rc 文件, 包括 MyProject.rc2。 .rc 2 文件是用于用户定义资源。 请按照下列步骤来增加每生成后 MyProject 的版本信息: 1. Remove the version resource from the .rc file and place it in the .rc2 file:
a. Open both MyProject.rc and MyProject.rc2 (found in the Res folder), in a text editor. To use the Visual C++ editor, click Open on the File menu and select Text in the Open As list for the MyProject.rc file. b. Find the version resource statements in MyProject.rc. It should look something like:
///////////////////////////////////////////////////////////////////////c. Cut the version resource from the MyProject.rc file and paste it into the MyProject.rc2 file below the comment "Add manually edited resources here." For information about what each one of the fields in the resource means, see the VERSIONINFO resource statement in Help. 2. Replace the FILEVERSION and PRODUCTVERSION data with macros FILEVER and PRODUCTVER. Similarly, replace the FileVersion and ProductVersion string data with the macros STRFILEVER and STRPRODUCTVER. 3. Add a #include VersionNo.h immediately before the VS_VERSION_INFO resource statement. Now the version resource will look like:
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Sample Application/0"
VALUE "CompanyName", "Microsoft Corp./0"
VALUE "FileDescription", "MyProject MFC Application/0"
VALUE "FileVersion", "1, 0, 0, 1/0"
VALUE "InternalName", "MyProject/0"
VALUE "LegalCopyright", "Copyright (C) 1999/0"
VALUE "OriginalFilename", "MyProject.EXE/0"
VALUE "ProductName", "MyProject Application/0"
VALUE "ProductVersion", "1, 0, 0, 1/0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
///////////////////////////////////////////////////////////////////////4. Create a header file called VersionNo.h in the same directory as your project. This file will contain the following statements, which are the definitions for macros used in step 2:
//
// Version
//
#include "VersionNo.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILEVER
PRODUCTVERSION PRODUCTVER
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Sample Application/0"
VALUE "CompanyName", "Microsoft Corp./0"
VALUE "FileDescription", "MyProject MFC Application/0"
VALUE "FileVersion", STRFILEVER
VALUE "InternalName", "MyProject/0"
VALUE "LegalCopyright", "Copyright (C) 1997/0"
VALUE "OriginalFilename", "MyProject.EXE/0"
VALUE "ProductName", "MyProject Application/0"
VALUE "ProductVersion", STRPRODUCTVER
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#define FILEVER 1,0,0,1NOTE: Add linefeed and carriage return characters on the last line.
#define PRODUCTVER 1,0,0,1
#define STRFILEVER "1, 0, 0, 1/0"
#define STRPRODUCTVER "1, 0, 0, 1/0"
Now, MyProject.rc file includes MyProject.rc2, and MyProject.rc2 file includes VersionNo.h. 5. The VersionNo.h file contents will be modified using a Visual Basic Script macro. The macro described below handles the Visual C++ BuildFinish event, so it will not be fired until a build completes. Whenever this VB Script code is called, it first increments the version numbers inside the header file by a fixed amount, then it saves the file and closes it. During a subsequent build, the new version number is included in the executable.
To install and use the VB Script code, do the following:
a. Open an existing DSM (macro) file or create a new DSM file in Visual C++. To create a new file, click New on the File menu, select Macro File on the Files tab, give it a name, and click OK. b. Paste the following VB Script code below (an empty DSM file cannot be installed in Visual C++; the next step explains installing):
Function GetProjectDir(FullName)NOTE: This code is an unsupported sample. You may modify it for your build scenario. c. Install the DSM file if it is not already installed. To install, click Customize on the Tools menu, click the Add-in and Macro Files tab, browse to select the DSM file, and click Close. 6. Select Build MyProject.exe from the Build menu. After the build finishes, open the VersionNo.h file. It will contain the following statements:
'VC++ doesn't provide any method for getting the path of the active project
'See the VB Script reference for more information on the VB Script functions
'used in this function
Dim proj_path
proj_path = Split(StrReverse(FullName),"/",-1,1)
Dim count
count = UBound(proj_path)
Dim full_path
full_path = ""
Dim i
for i = 1 to count
full_path = full_path & "/" & proj_path(i)
next
GetProjectDir = StrReverse(full_path)
End Function
Sub ReplaceText(selection, count, incrementby)
'selection represents the TextSelection object
'count represents the position of the version number to be incremented
'incrementby represents a number that will be added to the existing version number
selection.WordRight dsMove, count
selection.WordRight dsExtend, 1
Dim str
str = selection.Text
str = str + incrementby
selection.Text = str
End Sub
Sub Application_BuildFinish(numError, numWarning)
'This event will be triggered after every build of a project
'You can check numError and/or numWarning to determine if you want to continue
'If numError <> 0 Then
'exit sub
'Obtain the full path of the active project
Dim full_path
full_path = GetProjectDir(ActiveProject.FullName)
full_path = full_path & "versionno.h"
'Open the VersionNo.h file
Documents.Open full_path
'Obtain the TextSelection object
Dim selection
set selection = ActiveDocument.Selection
selection.StartOfDocument
'Increment the version information
ReplaceText selection, 9, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 9, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 10, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 10, 1
ActiveDocument.Save
ActiveDocument.Close
End Sub
#define FILEVER 1,0,0,2If you build the code again, this version information in included in the executable, and the version information is incremented. You can introduce some code in the macro described earlier to prevent incrementing version numbers if the build produced errors.
#define PRODUCTVER 1,0,0,2
#define STRFILEVER "1, 0, 0, 2/0"
#define STRPRODUCTVER "1, 0, 0, 2/0"
- 如何增加之后每 VisualC++ 中生成版本信息
- 如何增加在 Visual C++ 中的每个生成后的版本信息
- [版本构造]给delphi生成的软件增加版本信息
- 如何增加后每个版本的 Visual c + + 版本信息
- cocos2dx2.2版本之后,如何生成项目工程
- VisualC++中Debug和Release版本的区别
- VisualC++信息安全编程
- creatElement之后如何增加样式
- 如何在 VisualC # .NET 和 VisualC # 2005 中创建安装项目用于 Windows 服务应用程序
- [版本构造]给delphi生成的软件增加版本信息 续---编译乱码问题解决
- 如何在gridview中每10行记录后增加一个空行?
- 如何在gridview中每10行记录后增加一个空行?
- 如何禁用对 VisualC++ 中 CHtmlView 默认弹出式菜单
- 如何在VisualC++中检测和隔离内存泄漏
- Django 中如何给 User 增加额外的 Profile 信息
- 如何实现repeater中信息前自动增加序号
- MFC中如何生成release版本
- datagridview绑定数据之后如何增加行
- 编程中的次要问题 --编程珠玑学习笔记 第五章
- DataGrid滚动时当前记录不变
- DataGrid滚动时当前记录不变
- 考勤术语及规则定制
- 网页焦点的移动
- 如何增加之后每 VisualC++ 中生成版本信息
- linux嵌入式编程高手历程系列5-初识linux网桥
- 在ASP.NET中打印表格
- asp 跟什么数据库搭配好啊?
- log4j相关属性简介
- 一个比日本还要傻x的国家诞生了 (是中国人的一定要看!!!愤怒!!!)
- 在网页中与EXCEL的交互(导入)
- 当XML用selectSingleNode查找节点时,出现“未指定错误”时的处理
- Delphi面向对象编程的20条规则