I want to load the assembly version (the thing like 3.5.2.1) into a variable. the syntax is different than it was in VB6. Does anyone know how to do this in .net. I think its something to do with app.revision and stuff
John
Printable View
I want to load the assembly version (the thing like 3.5.2.1) into a variable. the syntax is different than it was in VB6. Does anyone know how to do this in .net. I think its something to do with app.revision and stuff
John
Copy-paste this at the end of your AssemblyInfo.vb
VB Code:
#Region " Helper Class to Get Information for the About form. " ' This class uses the System.Reflection.Assembly class to ' access assembly meta-data ' This class is not a normal feature of AssemblyInfo.vb Public Class AssemblyInfo ' Used by Helper Functions to access information from Assembly Attributes Private myType As Type Public Sub New() myType = GetType(frmLogin) End Sub Public ReadOnly Property AsmName() As String Get Return myType.Assembly.GetName.Name.ToString() End Get End Property Public ReadOnly Property AsmFQName() As String Get Return myType.Assembly.GetName.FullName.ToString() End Get End Property Public ReadOnly Property CodeBase() As String Get Return myType.Assembly.CodeBase End Get End Property Public ReadOnly Property Copyright() As String Get Dim at As Type = GetType(AssemblyCopyrightAttribute) Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False) Dim ct As AssemblyCopyrightAttribute = CType(r(0), AssemblyCopyrightAttribute) Return ct.Copyright End Get End Property Public ReadOnly Property Company() As String Get Dim at As Type = GetType(AssemblyCompanyAttribute) Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False) Dim ct As AssemblyCompanyAttribute = CType(r(0), AssemblyCompanyAttribute) Return ct.Company End Get End Property Public ReadOnly Property Description() As String Get Dim at As Type = GetType(AssemblyDescriptionAttribute) Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False) Dim da As AssemblyDescriptionAttribute = CType(r(0), AssemblyDescriptionAttribute) Return da.Description End Get End Property Public ReadOnly Property Product() As String Get Dim at As Type = GetType(AssemblyProductAttribute) Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False) Dim pt As AssemblyProductAttribute = CType(r(0), AssemblyProductAttribute) Return pt.Product End Get End Property Public ReadOnly Property Title() As String Get Dim at As Type = GetType(AssemblyTitleAttribute) Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False) Dim ta As AssemblyTitleAttribute = CType(r(0), AssemblyTitleAttribute) Return ta.Title End Get End Property Public ReadOnly Property Version() As String Get Return myType.Assembly.GetName.Version.ToString() End Get End Property End Class #End Region
Call like:
VB Code:
Dim ainfo As New AssemblyInfo() String.Format("Version {0}", ainfo.Version)
This code is pretty-much standardized in all 101 VB.Net Examples.
woah.. really?! maybe I didn't ask for the right thing then! I just want the simple like.. i guess version number of my program. like 1.2.0.0. I used to know how to get it, and it wasn't that long! it was just long concatinating a string with some periods.. any suggestions
Doesn't work that way anymore - you need to use Reflection (that's what this thing does).
ok thanks for clearing that up.. I'll try that. One quick thing.. That gets the assemble version, right? What about getting the 'publish version'. Is that easier/possible?
I don't know whether such a construct exists or not. If you're applying product version build numbers as part of a build process, the normal thing to do would be to change the assembly version so that your "product build" is embedded in that.
take it easy
Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString
Here is an example of how I put the Copyright Info and Version Number into a label:
Code:Me.lblVersion.Text = My.Application.Info.Trademark & " Version: " & _
My.Application.Info.Version.ToString