示例#1
0
        public static ApplicationVersionInfo GetApplicationVersionInfo(this Assembly assembly)
        {
            ApplicationVersionInfo info = new ApplicationVersionInfo()
            {
                Name                 = assembly.GetName().Name,
                Version              = assembly.GetName().Version.ToString(),
                Copyright            = assembly.GetCustomAttribute <AssemblyCopyrightAttribute>().Copyright,
                Description          = assembly.GetCustomAttribute <AssemblyDescriptionAttribute>().Description,
                FileVersion          = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version,
                FileCreationTime     = assembly.GetCreationTime().ToString("MMMM dd, yyyy HH:mm:ss"),
                InformationalVersion = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion,
                TargetFramework      = assembly.GetCustomAttribute <TargetFrameworkAttribute>().FrameworkName,
                Title                = assembly.GetCustomAttribute <AssemblyTitleAttribute>().Title,
                ImageRuntimeVersion  = assembly.ImageRuntimeVersion,
                Dependancies         = assembly.GetReferencedAssemblies().ToIEnumerableVersionInfo()
            };

            return(info);
        }
        public static ApplicationVersionInfo GetApplicationVersionInfo(this Assembly assembly, string commit = null)
        {
            DateTime creationTime = File.GetLastWriteTimeUtc(assembly.Location);

            ApplicationVersionInfo info = new ApplicationVersionInfo()
            {
                Name                 = assembly.GetName().Name,
                Version              = assembly.GetName().Version.ToString(),
                Copyright            = assembly.GetCustomAttribute <AssemblyCopyrightAttribute>().Copyright,
                Commit               = commit,
                Description          = assembly.GetCustomAttribute <AssemblyDescriptionAttribute>().Description,
                FileVersion          = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version,
                FileCreationTime     = creationTime.ToString("O"), // Use the round trip format as it includes the time zone.
                InformationalVersion = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion,
                TargetFramework      = assembly.GetCustomAttribute <TargetFrameworkAttribute>().FrameworkName,
                Title                = assembly.GetCustomAttribute <AssemblyTitleAttribute>().Title,
                ImageRuntimeVersion  = assembly.ImageRuntimeVersion,
                Dependancies         = assembly.GetReferencedAssemblies().ToIEnumerableVersionInfo()
            };

            return(info);
        }