标准版本号物理形式表示为用句点隔开的四段数字,如下面的代码示例所示。
<major version>.<minor version>.<build number>.<revision>

实际使用中,我们一般只用到前面三段。即
<major version>.<minor version>.<build number>

而且会分外部版本号和内部版本号:
<Version>
    <InternalVer>2.2.2</InternalVer>
    <ExternalVer>1.1.0</ExternalVer>
</Version>

程序显示的应该是外部版本号。
程序编译前用当前的内部版本号更新 AssemblyVersion 属性的 build number 段,非程序文件(如资源等)在打包、备份、打标签时统一使用内部版本号。

每个Assebmly包含三个Version
AssemblyFileVersion :存储在win32资源中, CLR不关心这个版本号,
AssemblyInformationnalVersion :存储在win32资源中, CLR不关心这个版本号,此版本号用来表示包含
Assembly的产品的版本
AssemblyVersion: 存储在AssemblyDef manifest metadata table中,CLR会使用这个版本号

工具的支持:
CSC.exe和AL.exe在每次build时可以自动增加AssemblyVersion, 但要慎用.改变一个Assembly的
AssemblyVersion会导致引用这个Assembly的其它Assembly无法工作.

在VS会为每一个.net Porject生成 AssemblyInfo.cs 可在其中设置相关的信息.
[assembly: AssemblyVersion(”1.0.0.0″)]
[assembly: AssemblyFileVersion(”1.0.1.0″)]
如果使用[assembly: AssemblyVersion(”1.0.*”)], 在每次程序修改后build或rebuild后, assembly的
AssemblyVersion的Build Number和 ReversionNumber和会自动增加.ReversionNumber每次都变,
Build Number随日期的变化而变化.

有没有什么工具可以显式地设置一个solution中所有的project的AssemblyVersion?

通过程序获得版本信息:
//== Get File Version
System.Diagnostics.FileVersionInfo.GetVersionInfo

//==Get Assembly Version
AssemblyName assName = Assembly.GetExecutingAssembly().GetName();
string version = assName.Version.ToString();

对于一个win32的exe或dll,在Explore中查看它的属性(Properties->Version)可以看到
File Version
Product Version

一个.net Assembly在Explore中查看它的属性(Properties->Version)可以看到
Assebly Version (对应 AssemblyVersion)
File Version (对应 AssemblyFileVersion)
Product Version (对应 AssemblyInformationnalVersion, 如果不指定,则和AssemblyFileVersion对应)



vc 修改版本号的脚本


Sub IncResVersion()
'DESCRIPTION: Build active project and increase version counter in rc script. Map it to F7 for ease of use. (c)'98 Th. Mahler

' open the project's resource script:
Documents.Open (ActiveProject.Name + ".rc"), "Text"
Windows(ActiveProject.Name + ".rc").Active = True
' find line with FileVersion Information:
ActiveDocument.Selection.FindText "VALUE ""FileVersion"",", dsMatchForward + dsMatchFromStart + dsMatchCase

' move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3

' mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 'dsExtend does not work in my VisualStudio???
Dim strVersion
strVersion = ActiveDocument.Selection.Text

' Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion , strVersion+1

'close RC file
ActiveDocument.Close()

'build active project
ExecuteCommand "BuildToggleBuild"
Documents.SaveAll True

End Sub
来源:
http://recordsome.blogsome.com/2006/06/
www.codeguru.com/Cpp/V-S/devstudio_macros/article.php/c3183


posted on 2007-05-16 11:24  凌度  阅读(1392)  评论(0编辑  收藏  举报