1 string fileContents = readFile(fName);
 2                 rgx = new Regex(pattern);
 3 
 4                 {
 5                     switch (verArg.Length)
 6                     {
 7                         case 4:  //<major version>.<minor version>.<build number>.<revision> 
 8                             replacement = String.Format("${{4}}{0}${{5}}{1}${{6}}{2}${{7}}{3}", verArg);
 9                             break;
10                         case 3:
11                             replacement = String.Format("${{3}}{0}${{4}}{1}${{5}}{2}", verArg);
12                             break;
13                         case 2:
14                             replacement = String.Format("${{2}}{0}${{3}}{1}", verArg);
15                             break;
16                         case 1:
17                             replacement = String.Format("${{1}}{0}", verArg);
18                             break;
19                     }
20                 }
21 
22  // Replace the build component of the AssemblyVersion attribute 
23                 // with the specified build number.
24                 fileContents = rgx.Replace(fileContents, replacement);
25 
26                 // reversion++
27                 if (ConfigurationManager.AppSettings["autoreversion"== "true")
28                 {
29                     // 读取匹配模式的行
30                     Match matchLine = rgx.Match(fileContents);
31                     string strLine = fileContents.Substring(matchLine.Groups[0].Index);
32                     strLine = strLine.Substring(0, strLine.IndexOf("\r\n"));
33               
34                     // 匹配四段版本号
35                     Regex regex = new Regex(@"(?<Major>[0-9]+)\s*[\.,]\s*(?<Minor>[0-9]+)\s*[\.,]\s*(?<Build>[0-9]+)\s*[\.,]\s*(?<Revision>[0-9]+)");
36                     Match m = regex.Match(strLine);
37 
38                     // 获取Revision
39                     string strRevision = m.Groups["Revision"].Value;
40                     string strLineNew = strLine.Substring(0, m.Groups["Revision"].Index);
41                     strLineNew += (int.Parse(strRevision) + 1) ;
42 
43                     // 更新编译序号
44                     fileContents = fileContents.Replace(strLine, strLineNew);
45 
46                 }
47                 // Open AssemblyVersionInfo file for Write access
48                 // Note: FileMode.Truncate effectively deletes the contents
49                 // of the file.
50                 WriteFile(fName, fileContents, true);

posted on 2007-05-24 19:36  凌度  阅读(1130)  评论(0编辑  收藏  举报