我想在标题栏上显示当前的BUILD信息

时间:2016-01-15 22:36:51

标签: .net vb.net winforms visual-studio

我想在标题栏上显示当前的BUILD信息。 (main_form.txt)。

我已经看过几个找到它的引用,但没有人给我我想要的数据。

我的项目是一个相当简单的visual studio express 2015,win forms app .net 4.5

当我查看属性/发布时,我看到构建当前是1.0.0.13 并且会增加每次发布。

我在哪里可以获得这些变量?

我在bbox2.exe.manifest文件中看到以下行....

asmv1:assemblyIdentity name =" bbox2.exe"版本=" 1.0.0.13"公钥=" 1d053a5b342cefc4"语言="中性" ........

我已按照以下其他帖子的建议尝试了以下内容。

    Dim ass As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
    Dim ver As System.Version = ass.GetName().Version
    Me.Text = ("BlacBox" & ver.Major & "." & ver.Minor & "." & ver.Revision & "." & ver.Build)

但总是让我1.0.0.0 ??

赞赏任何建议。

1 个答案:

答案 0 :(得分:2)

使用点击一次发布应用程序时,Publish Version可用,否则您可以在AssemblyVersion文件夹下的AssemblyInfo.vb中使用My Project的值。

与发布版本一样,您可以使用<Assembly: AssemblyVersion("1.0.*")><Assembly: AssemblyVersion("1.0.0.*")>自动设置程序集版本。您还可以将主要版本,次要版本和构建版本更改为合适的值。

您可以创建一个以这种方式返回版本字符串的属性:

Public ReadOnly Property ApplicationVersion As Version
    Get
        If (ApplicationDeployment.IsNetworkDeployed) Then
            Return ApplicationDeployment.CurrentDeployment.CurrentVersion
        Else
            Return Assembly.GetExecutingAssembly().GetName().Version
        End If
    End Get
End Property

不要忘记添加对System.Deployment程序集的引用,并将import namespace添加到代码中:

Imports System.Deployment.Application

然后你可以使用:

Me.Text = ApplicationVersion.ToString()

或者要以自定义格式显示版本,您可以使用MajorMinorBuildRevision,例如显示内置版本号的版本:

Me.Text = String.Format("{0}.{1}.{2}", _
          ApplicationVersion.Major, ApplicationVersion.Minor, ApplicationVersion.Build)

修改

  

OP:I am not using click once.

因此,您应该在AssemblyVersion AssemblyInfo.vb下的My Project文件夹中使用<Assembly: AssemblyVersion("1.0.*")>,并将其更改为Me.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString() ,以使其自动增加。然后你可以这样得到版本:

Imports System.Reflection

不要忘记apply