Table of Contents

TargetFrameworkMoniker Class

Definition

Provides a set of static methods for resolving target framework monikers from assemblies and the current application context.

public static class TargetFrameworkMoniker
Inheritance
object
TargetFrameworkMoniker

Examples

TargetFrameworkMoniker parses and resolves short target framework names such as net10.0, net9.0, netstandard2.0, and net481 from framework names, assemblies, paths, or the current application context.

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

namespace MyApp.Examples;

public class TargetFrameworkMonikerExample
{
    public void Demonstrate()
    {
        var parsed = TargetFrameworkMoniker.Parse(".NETCoreApp,Version=v10.0");
        var current = TargetFrameworkMoniker.ResolveCurrent();
        var library = TargetFrameworkMoniker.Resolve(typeof(TargetFrameworkMonikerExample).Assembly);
        var outputPath = TargetFrameworkMoniker.ResolveFromPath(AppContext.BaseDirectory);

        Console.WriteLine($"Parsed TFM: {parsed}");
        Console.WriteLine($"Current TFM: {current}");
        Console.WriteLine($"Example assembly TFM: {library}");
        Console.WriteLine($"Output path TFM: {outputPath}");

        if (TargetFrameworkMoniker.TryResolve(Assembly.GetExecutingAssembly(), out var executingAssemblyTfm))
        {
            Console.WriteLine($"Executing assembly TFM: {executingAssemblyTfm}");
        }
    }
}

Methods

Name Description
Parse(FrameworkName)

Parses the specified frameworkName into its short target framework moniker representation.

Parse(string)

Parses the specified frameworkNameOrTargetFrameworkMoniker into its short target framework moniker representation.

Resolve(Assembly)

Resolves the target framework moniker of the specified assembly.

ResolveCurrent()

Resolves the target framework moniker of the current application context.

ResolveFromPath(string)

Resolves the nearest target framework moniker found in the specified path.

TryParse(FrameworkName, out string)

Attempts to parse the specified frameworkName into its short target framework moniker representation.

TryParse(string, out string)

Attempts to parse the specified frameworkNameOrTargetFrameworkMoniker into its short target framework moniker representation.

TryResolve(Assembly, out string)

Attempts to resolve the target framework moniker of the specified assembly.

TryResolveCurrent(out string)

Attempts to resolve the target framework moniker of the current application context.

TryResolveFromPath(string, out string)

Attempts to resolve the nearest target framework moniker found in the specified path.