Skip to content

Insert version into title bar text #23

@skst

Description

@skst

We want to append the product version to the text in the title bar of the License Manager X app. You can use the ApplicationInformation.cs class included below.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;


namespace Shared;

/// <summary>
/// For additional assemblies, derive a class and add more FileVersionInfo members.
/// </summary>
/// <example>
/// public FileVersionInfo MyLibraryExeInfo { get; private set; }
///
/// string pathLibraryDLL = System.IO.Path.Combine(pathExe, "MyLibrary.dll");
/// LibraryDLLInfo = FileVersionInfo.GetVersionInfo(pathCoreDLL);
/// </example>
public class ApplicationInformation
{
        public string Name { get; private set; }
        public string Company { get; private set; }
        public string Copyright { get; private set; }
        public string Version { get; private set; }

        public string FileTitle { get; private set; }
        public string FileVersion{ get; private set; }

        public string WebSiteURL { get; private set; } = @"https://12noon.com";

        // AssemblyDescription
        // AssemblyConfiguration
        // AssemblyTrademark
        // AssemblyInformationalVersion

        /// <summary>
        /// Provides information about the version of the EXECUTING assembly.
        /// </summary>
        /// <remarks>
        /// This does NOT return information about THIS assembly (DLL).
        /// </remarks>
        public ApplicationInformation()
        {
                Assembly asm = Assembly.GetEntryAssembly() ?? throw new ArgumentNullException(nameof(Assembly));
                //string pathExe = Path.GetDirectoryName(asm.Location);

                // Get information about this assembly (not necessarily the executing assembly).
                FileVersionInfo AppExeInfo = FileVersionInfo.GetVersionInfo(asm.Location);

                //AssemblyName asmName = asm.GetName();

                //AssemblyTitleAttribute attrTitle = (AssemblyTitleAttribute)System.Attribute.GetCustomAttribute(asm, typeof(AssemblyTitleAttribute));
                //string Title = attrTitle.Title;

                //AssemblyCompanyAttribute attrCompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(asm, typeof(AssemblyCompanyAttribute));
                //Company = attrCompany.Company;

                Name = AppExeInfo.ProductName ?? string.Empty;
                Company = AppExeInfo.CompanyName ?? string.Empty;
                Copyright = AppExeInfo.LegalCopyright ?? string.Empty;
                Version = AppExeInfo.ProductVersion ?? string.Empty;

                FileTitle = AppExeInfo.FileDescription ?? string.Empty;
                FileVersion = AppExeInfo.FileVersion ?? string.Empty;
        }


        /// <summary>
        /// Return the path to the main (entry) assembly (.exe).
        /// (NOT including the filename of the executable).
        /// </summary>
        /// <example>
        /// C:\Path\To\Executable
        /// </example>
        /// <see cref="Assembly.GetEntryAssembly" />
        /// <seealso cref="Assembly.GetExecutingAssembly" />
        /// <returns>Path of the main (entry) assembly (.exe)</returns>
        public static string GetAssemblyPath()
        {
                Assembly? asm = Assembly.GetEntryAssembly();
                return Path.GetDirectoryName(asm?.Location) ?? string.Empty;
        }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions