重庆熊猫 Loading

C#.NET中的程序集版本

更新记录
2022年4月16日:本文迁移自Panda666原博客,原发布时间:2021年8月22日。

在Visual Studio中查看程序集版本

image

在程序运行中获得程序集版本信息

除了在Visual Studio中查看版本信息,在程序运行中也可以通过反射获得指定程序集的版本信息。

下面以获得当前正在运行的程序集的版本为例。您在具体的项目中可以加载您需要的程序集。

using System;
using System.Reflection;

namespace Panda666ComTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //获得当前正在执行的程序集
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            //获得当前程序集的版本对象
            var versionObject = currentAssembly.GetName().Version;
            //获得当前程序集的版本号字符串
            string version = versionObject.ToString();
            //获得当前程序集的最后修改时间   string dateTime = System.IO.File.GetLastWriteTime(currentAssembly.Location).ToString();

            Console.WriteLine($"版本号:{version}");
            Console.WriteLine($"程序集发布时间:{dateTime}");
        }
    }
}
posted @ 2022-04-16 19:03  重庆熊猫  阅读(120)  评论(0编辑  收藏  举报