From 2919fcff821f2c9beec117895bc72e5b152447b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 6 May 2024 22:27:19 +0200 Subject: [PATCH] Fix NUnit extension version Use AssemblyInformationalVersionAttribute version or fallback to AssemblyVersion instead of using hardcoded version. --- .../TestingPlatformAdapter/NUnitExtension.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/NUnitTestAdapter/TestingPlatformAdapter/NUnitExtension.cs b/src/NUnitTestAdapter/TestingPlatformAdapter/NUnitExtension.cs index d5b1f35c..945db332 100644 --- a/src/NUnitTestAdapter/TestingPlatformAdapter/NUnitExtension.cs +++ b/src/NUnitTestAdapter/TestingPlatformAdapter/NUnitExtension.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Reflection; +using System.Threading.Tasks; using Microsoft.Testing.Platform.Extensions; @@ -10,11 +11,18 @@ internal sealed class NUnitExtension : IExtension public string DisplayName => "NUnit"; - // TODO: Decide whether to read from assembly or use hardcoded string. - public string Version => "4.5.0"; + public string Version { get; } = GetAssemblyVersion(); public string Description => "NUnit adapter for Microsoft Testing Platform"; public Task IsEnabledAsync() => Task.FromResult(true); + + private static string GetAssemblyVersion() + { + var assembly = typeof(NUnitExtension).Assembly; + var version = assembly.GetCustomAttribute()?.InformationalVersion + ?? assembly.GetName().Version?.ToString(); + return version; + } } }