vb.net 获得版本信息

原文来自: http://blog.163.com/xhy_cy/blog/static/10497623201132242513577/

和 http://blog.163.com/xhy_cy/blog/static/10497623201132243059238/?suggestedreading&wumii

 

1 如何获取和修改EXE、DLL文件的版本、公司、描述等信息  

'AssemblyTitle取得
Dim asmttl As System.Reflection.AssemblyTitleAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyTitleAttribute)), _
            System.Reflection.AssemblyTitleAttribute)
Console.WriteLine(asmttl.Title)

'AssemblyDescription取得
Dim asmdc As System.Reflection.AssemblyDescriptionAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyDescriptionAttribute)), _
            System.Reflection.AssemblyDescriptionAttribute)
Console.WriteLine(asmdc.Description)

'AssemblyCompany取得
Dim asmcmp As System.Reflection.AssemblyCompanyAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyCompanyAttribute)), _
            System.Reflection.AssemblyCompanyAttribute)
Console.WriteLine(asmcmp.Company)

'AssemblyProduct取得
Dim asmprd As System.Reflection.AssemblyProductAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyProductAttribute)), _
            System.Reflection.AssemblyProductAttribute)
Console.WriteLine(asmprd.Product)

'AssemblyCopyright取得
Dim asmcpy As System.Reflection.AssemblyCopyrightAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyCopyrightAttribute)), _
            System.Reflection.AssemblyCopyrightAttribute)
Console.WriteLine(asmcpy.Copyright)

'AssemblyTrademark取得
Dim asmtmk As System.Reflection.AssemblyTrademarkAttribute = _
    CType(Attribute.GetCustomAttribute( _
        System.Reflection.Assembly.GetExecutingAssembly(), _
        GetType(System.Reflection.AssemblyTrademarkAttribute)), _
            System.Reflection.AssemblyTrademarkAttribute)
Console.WriteLine(asmtmk.Trademark)

要修改的话,只能通过VisualStudio来设定。也许通过Win32API可以吧。

 

 

 

2读取C# AssemblyInfo文件中的AssemblyVersion中的值  

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()

上一篇:asp.net常用javascript封装代码


下一篇:Kubernetes NodePort、LoadBalancer和Ingress介绍