Table of Contents

AssemblyExtensions Class

Definition

Namespace
Cuemon.Extensions.Reflection
Assemblies
Cuemon.Extensions.Reflection.dll
Source
src/Cuemon.Extensions.Reflection/AssemblyExtensions.cs

Extension methods for the Assembly class.

public static class AssemblyExtensions
Inheritance
AssemblyExtensions

Examples

AssemblyExtensions provides extension methods for Assembly to retrieve version information and debug-build status. This example obtains the entry assembly and calls GetAssemblyVersion, GetFileVersion, and GetProductVersion to read version attributes, then checks HasAlphanumericVersion and IsSemanticVersion() on the returned SourceVersion objects. It also calls IsDebugBuild() to determine whether the assembly was compiled in Debug configuration. Console output displays each version string (e.g., 1.0.0.0), whether it has alphanumeric or semantic version characteristics, and the debug-build flag.

using System;
using System.Reflection;
using Cuemon.Extensions.Reflection;

namespace MyApp.Reflection
{
    public class AssemblyExtensionsExample
    {
        public void Demonstrate()
        {
            var assembly = typeof(AssemblyExtensionsExample).Assembly;

            // Get the assembly version (from AssemblyVersionAttribute)
            var assemblyVersion = assembly.GetAssemblyVersion();
            Console.WriteLine($"Assembly version: {assemblyVersion}"); // e.g., "1.0.0.0"
            Console.WriteLine($"Has alphanumeric version: {assemblyVersion.HasAlphanumericVersion}"); // False
            Console.WriteLine($"Is semantic version: {assemblyVersion.IsSemanticVersion()}"); // False

            // Get the file version (from AssemblyFileVersionAttribute)
            var fileVersion = assembly.GetFileVersion();
            Console.WriteLine($"File version: {fileVersion}"); // e.g., "1.0.0.0"

            // Get the product version (from AssemblyInformationalVersionAttribute)
            var productVersion = assembly.GetProductVersion();
            Console.WriteLine($"Product version: {productVersion}"); // e.g., "1.0.0"
            Console.WriteLine($"Has alphanumeric version: {productVersion.HasAlphanumericVersion}"); // True (usually)
            Console.WriteLine($"Is semantic version: {productVersion.IsSemanticVersion()}"); // True

            // Check if the assembly is a debug build
            var isDebug = assembly.IsDebugBuild();
            Console.WriteLine($"Is debug build: {isDebug}"); // True in Debug, False in Release

}}
}

Methods

Name Description
GetAssemblyVersion(Assembly)

Returns a VersionResult that represents the version number of the specified assembly.

GetFileVersion(Assembly)

Returns a VersionResult that represents the file version number of the specified assembly.

GetProductVersion(Assembly)

Returns a VersionResult that represents the version of the product this assembly is distributed with.

IsDebugBuild(Assembly)

Determines whether the specified assembly is a debug build.