Results 1 to 8 of 8

Thread: Assembly Version

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Assembly Version

    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

  2. #2
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Assembly Version

    Copy-paste this at the end of your AssemblyInfo.vb
    VB Code:
    1. #Region " Helper Class to Get Information for the About form. "
    2. ' This class uses the System.Reflection.Assembly class to
    3. ' access assembly meta-data
    4. ' This class is not a normal feature of AssemblyInfo.vb
    5. Public Class AssemblyInfo
    6.     ' Used by Helper Functions to access information from Assembly Attributes
    7.     Private myType As Type
    8.  
    9.     Public Sub New()
    10.         myType = GetType(frmLogin)
    11.     End Sub
    12.  
    13.     Public ReadOnly Property AsmName() As String
    14.         Get
    15.             Return myType.Assembly.GetName.Name.ToString()
    16.         End Get
    17.     End Property
    18.     Public ReadOnly Property AsmFQName() As String
    19.         Get
    20.             Return myType.Assembly.GetName.FullName.ToString()
    21.         End Get
    22.     End Property
    23.     Public ReadOnly Property CodeBase() As String
    24.         Get
    25.             Return myType.Assembly.CodeBase
    26.         End Get
    27.     End Property
    28.     Public ReadOnly Property Copyright() As String
    29.         Get
    30.             Dim at As Type = GetType(AssemblyCopyrightAttribute)
    31.             Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False)
    32.             Dim ct As AssemblyCopyrightAttribute = CType(r(0), AssemblyCopyrightAttribute)
    33.             Return ct.Copyright
    34.         End Get
    35.     End Property
    36.     Public ReadOnly Property Company() As String
    37.         Get
    38.             Dim at As Type = GetType(AssemblyCompanyAttribute)
    39.             Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False)
    40.             Dim ct As AssemblyCompanyAttribute = CType(r(0), AssemblyCompanyAttribute)
    41.             Return ct.Company
    42.         End Get
    43.     End Property
    44.     Public ReadOnly Property Description() As String
    45.         Get
    46.             Dim at As Type = GetType(AssemblyDescriptionAttribute)
    47.             Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False)
    48.             Dim da As AssemblyDescriptionAttribute = CType(r(0), AssemblyDescriptionAttribute)
    49.             Return da.Description
    50.         End Get
    51.     End Property
    52.     Public ReadOnly Property Product() As String
    53.         Get
    54.             Dim at As Type = GetType(AssemblyProductAttribute)
    55.             Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False)
    56.             Dim pt As AssemblyProductAttribute = CType(r(0), AssemblyProductAttribute)
    57.             Return pt.Product
    58.         End Get
    59.     End Property
    60.     Public ReadOnly Property Title() As String
    61.         Get
    62.             Dim at As Type = GetType(AssemblyTitleAttribute)
    63.             Dim r() As Object = myType.Assembly.GetCustomAttributes(at, False)
    64.             Dim ta As AssemblyTitleAttribute = CType(r(0), AssemblyTitleAttribute)
    65.             Return ta.Title
    66.         End Get
    67.     End Property
    68.     Public ReadOnly Property Version() As String
    69.         Get
    70.             Return myType.Assembly.GetName.Version.ToString()
    71.         End Get
    72.     End Property
    73. End Class
    74.  
    75. #End Region

    Call like:

    VB Code:
    1. Dim ainfo As New AssemblyInfo()
    2. String.Format("Version {0}", ainfo.Version)

    This code is pretty-much standardized in all 101 VB.Net Examples.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: Assembly Version

    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

  4. #4
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Assembly Version

    Doesn't work that way anymore - you need to use Reflection (that's what this thing does).
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: Assembly Version

    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?

  6. #6
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Assembly Version

    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.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  7. #7
    New Member
    Join Date
    Jan 2007
    Posts
    1

    Wink Re: Assembly Version

    take it easy
    Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString

  8. #8
    New Member
    Join Date
    Jun 2007
    Posts
    2

    Re: Assembly Version

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width