VS_VERSION_INFO

本文详细解析了IDE中编辑VS_VERSION_INFO时各选项的含义及区别,包括FileVersion、ProductName、PrivateBuild、SpecialBuild等,并提供了一个PE文件版本信息查询工具的实现案例。此外,还分享了如何使用此工具来检查和修正文件版本信息,便于源码控制和版本追踪。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在IDE中编辑VS_VERSION_INFO, 有些选项不知道含义. 有些选项含义相近,不知道区别.

现在代码提交前要设置代码版本号,

FileVersion, ProductName的区别?
PrivateBuild, SpecialBuild的区别?

读取文件版本号的实验,整理过. 现在找到了更好的资料:

Class Wrapper to Retrieve Module Information (VS_VERSION_INFO Resource)
http://www.codeguru.com/cpp/misc/misc/versioninfo/article.php/c3823

在codeproject上搜索'VS_VERSION_INFO', 有vside自动增加版本号的例子, 这个实验要做一下.

<2010_1223>

这个demo在XpSp3上运行不过, 以这个程序做原型,做个工具来查看文件的版本信息, UI要比原来的好看.

用这个工具来查看发行的可执行文件, 可以把漏掉的版本选项检查出来. 从而修正原来的exe的rc信息. 便于从exe来查找文件的源码控制对应的版本.

看了一些Demo, 最后都调用的是MS SDK 中的Version API.

ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/winui/winui/windowsuserinterface/resources/versioninformation.htm

<2010_1224>

又找了些资料,整合了一个PE文件版本信息查询工具.UI做的很漂亮.

能查询的版本信息:

运行效果图:

工程已上传: http://download.youkuaiyun.com/source/2933816

手工在IDE中填写Vs_VERSION_INFO, 各项含义如下:

StringMeaning
CommentsThe Value member contains any additional information that should be displayed for diagnostic purposes. This string can be an arbitrary length.
CompanyNameThe Value member identifies the company that produced the file. For example, "Microsoft Corporation" or "Standard Microsystems Corporation, Inc."
FileDescriptionThe Value member describes the file in such a way that it can be presented to users. This string may be presented in a list box when the user is choosing files to install. For example, "Keyboard driver for AT-style keyboards" or "Microsoft Word for Windows".
FileVersionThe Value member identifies the version of this file. For example, Value could be "3.00A" or "5.00.RC2".
InternalNameThe Value member identifies the file's internal name, if one exists. For example, this string could contain the module name for a dynamic-link library (DLL), a virtual device name for a Windows virtual device, or a device name for an MS-DOS device driver.
LegalCopyrightThe Value member describes all copyright notices, trademarks, and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, trademark numbers, and so on. In English, this string should be in the format "Copyright Microsoft Corp. 1990–1994".
LegalTrademarksThe Value member describes all trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. In English, this string should be in the format "Windows is a trademark of Microsoft Corporation".
OriginalFilenameThe Value member identifies the original name of the file, not including a path. This enables an application to determine whether a file has been renamed by a user. This name may not be MS-DOS 8.3-format if the file is specific to a non-FAT file system.
PrivateBuildThe Value member describes by whom, where, and why this private version of the file was built. This string should only be present if the VS_FF_PRIVATEBUILD flag is set in the dwFileFlags member of the VS_FIXEDFILEINFO structure. For example,Value could be "Built by OSCAR on /OSCAR2".
ProductNameThe Value member identifies the name of the product with which this file is distributed. For example, this string could be "Microsoft Windows".
ProductVersionThe Value member identifies the version of the product with which this file is distributed. For example, Value could be "3.00A" or "5.00.RC2".
SpecialBuildThe Value member describes how this version of the file differs from the normal version. This entry should only be present if the VS_FF_SPECIALBUILD flag is set in the dwFileFlags member of the VS_FIXEDFILEINFO structure. For example, Valuecould be "Private build for Olivetti solving mouse problems on M250 and M250E computers".
<think>好的,我现在需要帮用户解决如何将VS_VERSION_INFO嵌入到生成的lib文件中。首先,我得理解VS_VERSION_INFO是什么。这是Windows资源文件中的一个结构,用于存储版本信息,比如文件版本、产品名称等。通常用于DLL或EXE文件,但用户提到的是lib文件,也就是静态库。静态库在Windows下一般是.lib文件,而动态库是DLL。 用户的问题是如何在构建过程中将这些版本信息写入lib文件中。根据我的知识,静态库(.lib)本身不包含资源信息,因为资源通常是在链接成可执行文件或DLL时添加的。所以可能需要考虑在创建静态库时,将资源信息包含进去,使得当这个lib被链接到DLL或EXE时,版本信息也随之携带。 接下来,我需要回忆相关的方法。在Visual Studio项目中,通常通过.rc文件来添加资源。所以可能的步骤是创建一个包含VS_VERSION_INFO的.rc文件,然后将这个资源编译成.res文件,再将其链接到静态库中。不过静态库是否支持包含资源呢?可能需要验证一下。 查阅之前的引用内容,用户提供的引用[1]提到构建静态二进制文件,引用[2]涉及CMake的文件操作,引用[3]和[4]关于构建类型和库的创建,可能不直接相关。但用户的问题是关于嵌入版本信息到lib,所以可能需要结合CMake或Visual Studio的配置。 在Visual Studio中,静态库项目默认不处理资源文件,所以需要手动配置。可能的步骤是:添加资源文件(.rc)到项目,配置项目属性,确保资源编译器处理.rc文件,生成.res文件,并将.res文件链接到lib中。或者,可能需要将资源编译成.obj文件,然后静态库包含这个.obj。 另外,使用CMake的话,如何配置呢?在CMakeLists.txt中添加资源文件,并确保资源被编译和链接。例如,使用add_custom_command生成资源,然后将其加入库的源文件列表中。 比如,假设有一个version.rc文件,其中包含VS_VERSION_INFO结构。在CMake中,可以使用以下命令: enable_language(RC) add_library(mylib STATIC source.cpp version.rc) 这样CMake会自动调用资源编译器处理.rc文件,并将其链接到库中。但需要确认静态库是否真的包含这些资源信息。可能需要测试。 此外,如果用户使用的是纯命令行编译,可能需要手动调用rc.exe编译.rc为.res,然后通过lib.exe将.res添加到.lib中。但通常静态库的生成不包含资源,可能需要将资源作为对象文件包含进去。例如: rc.exe /fo version.res version.rc lib.exe /out:mylib.lib mylib.obj version.res 但不确定这种方法是否有效,因为资源通常是在链接为DLL或EXE时处理的。可能需要进一步验证。 总结可能的解决方案: 1. 在Visual Studio项目中添加.rc文件,并配置项目属性,使资源编译并包含到静态库中。 2. 使用CMake配置,将.rc文件作为源文件加入库中,确保资源被编译。 3. 手动编译资源文件并链接到库中,可能需要将.res文件转换为.obj或直接包含。 需要验证这些方法的有效性,特别是静态库是否能够正确携带资源信息。如果静态库本身不支持资源,可能需要考虑其他方式,比如将资源信息嵌入到代码中,或者确保在使用该库的应用程序中链接资源文件。</think>在Windows平台下将$VS\_VERSION\_INFO$嵌入生成的静态库文件(.lib),需要通过资源文件(.rc)编译并链接到目标库中。以下是具体实现方法: ### 一、Visual Studio工程配置方法 1. **创建版本资源文件** 新建`version.rc`文件,内容示例: ```rc #include <winver.h> VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,1 PRODUCTVERSION 1,0,0,1 FILEFLAGSMASK 0x3fL FILEFLAGS 0x0L FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL FILESUBTYPE VFT2_UNKNOWN BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", "My Static Library" VALUE "FileVersion", "1.0.0.1" VALUE "ProductName", "MyProject" VALUE "ProductVersion", "1.0.0.1" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0409, 1200 END END ``` 2. **添加资源到静态库项目** - 在解决方案资源管理器中右键项目 → 添加 → 现有项 → 选择`version.rc` - 打开项目属性 → **配置属性 → 资源** → 确保`.rc`文件被包含在资源编译流程中 3. **验证资源编译** 构建后检查输出目录是否生成`.res`文件,该文件会被自动链接到最终的`.lib`中[^1] ### 二、CMake跨平台配置方法 ```cmake cmake_minimum_required(VERSION 3.15) project(mylib) # 启用资源编译器 enable_language(RC) # 添加资源文件 add_library(mylib STATIC src/source.cpp version.rc ) # 设置资源文件属性 set_source_files_properties(version.rc PROPERTIES LANGUAGE RC COMPILE_FLAGS "/nologo /fo ${CMAKE_CURRENT_BINARY_DIR}/version.res" ) ``` ### 三、手动编译验证方法 ```bat :: 编译资源文件 rc.exe /fo version.res version.rc :: 将资源文件与目标库链接 lib.exe /OUT:mylib.lib mylib.obj version.res ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值