zoukankan      html  css  js  c++  java
  • C#中获取程序集版本号的方法

    我的方法:string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
     
    方法一:
    public void GetFileVersion() {
    FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Path路径字符串);
    string AssmblyVersion=myFileVersionInfo.FileVersion;
    }  

    方法二:
    [assembly: AssemblyTitle("")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("")]
    [assembly: AssemblyProduct("")]
    [assembly: AssemblyCopyright("")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyCulture("")]
    修改AssemblyInfo.cs文件的上述信息

    在程序中调用如下:
    Version ApplicationVersion = new Version(Application.ProductVersion);
    string AssmblyVersion = ApplicationVersion.Major;//获取主版本号  

    方法三:
    private void GetEdition()
    {
    Assembly assembly = Assembly.GetExecutingAssembly();
    //this.labelEdition.Text = assembly.FullName;

    // 获取程序集元数据
    AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute)
    AssemblyCopyrightAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),
    typeof(AssemblyCopyrightAttribute));
    AssemblyDescriptionAttribute description = (AssemblyDescriptionAttribute)
    AssemblyDescriptionAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(),
    typeof(AssemblyDescriptionAttribute)); 

    string a = description.Description;
    string b = description.Description; 
    string c = copyright.Copyright; 
    string d = Application.ProductVersion;
    }

    方法四:
    string path = @"C:WINNTMicrosoft.NETFrameworkv1.1.4322System.dll";
    Assembly assembly = Assembly.LoadFile(path);
    AssemblyName assemblyName = assembly.GetName();
    Version version = assemblyName.Version;
    Console.WriteLine(assemblyName.FullName);
    string a=version.Major.ToString();
    string b= version.Minor.ToString(); 
    string c=version.Revision.ToString(); 
    string d=version.Build.ToString(); 

    只要得到Assembly ,剩下的都好说,
    楼主可以看看Assembly的几个静态方法,应该可以满足所有需要了
    比如
    //得到Mscorlib.dll
    Assembly.GetAssembly(typeof(string))   
  • 相关阅读:
    截取字符串
    VC++ PathFindFileName函数,由文件路径获得文件名
    获取GetOpenFileName多选文件名
    WideCharToMultiByte和MultiByteToWideChar函数的用法(转载)
    map set iterator not incrementable 解决办法
    定义c/c++全局变量/常量几种方法的区别(转载)
    如何禁止同IP站点查询和同IP站点查询的原理分析 Robots.txt屏蔽BINGBOT
    JavaScript 文件操作方法详解
    nginx日志配置
    php的strip_tags,htmlspecialchars,htmlentities,stripslashes,addslashes解释
  • 原文地址:https://www.cnblogs.com/Rmeo/p/3491319.html
Copyright © 2011-2022 走看看