针对Visual Studio 6.0开发环境:
标准情况下在“【工程名】.rc”文件中写入版本号;也允许使用每次编译自动加1宏在VersionNo.h中写入版本号。在新建项目时必须选择其中一种!
u
标准rc文件:
FILEVERSION
1,0,0,1
VALUE
"FileVersion", "1, 0, 0, 1"
u
标准VersionNo.h:
#define
FILEVER 1,0,0,1
针对Visual Studio .net开发环境
托管环境: 必须建立AssemblyInfo文件,不允许修改AssemblyVersion,只修改AssemblyFileVersion
非托管环境:和Visual Studio 6.0开发环境一致,建立*.rc或VersionNo.h文件
u
标准AssemblyInfo.cs
[assembly:
AssemblyFileVersion("
u
标准AssemblyInfo.vb
<assembly:
AssemblyFileVersion("
标准版本号物理形式表示为用句点(/逗号)隔开的四段数字,如下面的代码示例所示。
<major version>.<minor version>.<build number>.<revision>
case 1: <major version>
case 2: <major version>.<minor version>
case 3: <major version>.<minor version>.<build number>
case 4: <major version>.<minor version>.<build
number>.<revision>
2 {
3 case 4:
4 replacement = String.Format("${{4}}{0}${{5}}{1}${{6}}{2}${{7}}{3}${{8}}", verArg);
5 break;
6 case 3:
7 replacement = String.Format("${{3}}{0}${{4}}{1}${{5}}{2}${{6}}", verArg);
8 break;
9 case 2:
10 replacement = String.Format("${{2}}{0}${{3}}{1}${{4}}", verArg);
11 break;
12 case 1:
13 replacement = String.Format("${{1}}{0}${{2}}", verArg);
14 break;
15 }
正则表达式替换版本号
2 // AssemblyVersion attribute with the specified build number.
3 rgx = new Regex(pattern);
4
5 // Replace the build component of the AssemblyVersion attribute
6 // with the specified build number.
7 fileContents = rgx.Replace(fileContents, replacement);
app.config(只举了case 2和case 4的例子)
2 <add key="buildVerFileNum" value="5"/>
3 <add key="buildVerFileNum1" value="VersionNo.h" /> <!-- 这时可能存在*.rc2 -->
4 <add key="buildVerFileNum2" value=".rc" />
5 <add key="buildVerFileNum3" value=".rc2" />
6 <add key="buildVerFileNum4" value="AssemblyInfo.vb" />
7 <add key="buildVerFileNum5" value="AssemblyInfo.cs" />
8
9
10 <!-- 与上面的文件名对应的匹配模式 -->
11 <!-- 更改四段版本号 -->
12 <!-- add key="pattern1" value="(?<4>#define\sFILEVER\s+)[0-9]+(?<5>[\.,])[0-9]+(?<6>[\.,])[0-9]+(?<7>[\.,])[0-9]+(?<8>[\r\n])"/>
13 <add key="pattern2" value="(?<4>FILEVERSION\s+)[0-9]+(?<5>[\.,])[0-9]+(?<6>[\.,])[0-9]+(?<7>[\.,])[0-9]+(?<8>[\r\n])"/>
14 <add key="pattern3" value="(?<4>assembly:\sAssemblyVersion\(")[0-9]+(?<5>[\.,])[0-9]+(?<6>[\.,])[0-9]+(?<7>[\.,])[0-9]+(?<8>")"/>
15 <add key="pattern4" value="(?<4>assembly:\sAssemblyVersion\(")[0-9]+(?<5>[\.,])[0-9]+(?<6>[\.,])[0-9]+(?<7>[\.,])[0-9]+(?<8>")"/ -->
16 <!-- 更改<major version>.<minor version> -->
17 <add key="pattern1" value="(?<2>#define\sFILEVER\s+)[0-9]+(?<3>[\.,])[0-9]+(?<4>[\.,])"/>
18 <add key="pattern2" value="(?<2>FILEVERSION\s+)[0-9]+(?<3>[\.,])[0-9]+(?<4>[\.,])"/>
19 <add key="pattern3" value="(?<2>VALUE\s+"FileVersion"[\.,]\s*")[0-9]+(?<3>[\.,]\s*)[0-9]+(?<4>[\.,]\s*)"/>
20 <add key="pattern4" value="(?<2>assembly:\sAssemblyVersion\(")[0-9]+(?<3>[\.,])[0-9]+(?<4>[\.,])"/>
21 <add key="pattern5" value="(?<2>assembly:\sAssemblyVersion\(")[0-9]+(?<3>[\.,])[0-9]+(?<4>[\.,])"/>