Split for + when parsing version (#646)
This commit is contained in:
Родитель
136aeeb68a
Коммит
8ca6bab411
|
@ -1,36 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static string FullVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
var attribute = typeof(Constants).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
return attribute?.InformationalVersion ?? "0.0.0-unspecified";
|
||||
}
|
||||
}
|
||||
|
||||
public static Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
var version = FullVersion;
|
||||
var idx = version.IndexOf('-', StringComparison.Ordinal);
|
||||
|
||||
if (idx > 0)
|
||||
{
|
||||
version = version.Substring(0, idx);
|
||||
}
|
||||
|
||||
return Version.Parse(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -135,7 +135,7 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
|
||||
private class UpgradeState
|
||||
{
|
||||
public string Build { get; init; } = Constants.FullVersion;
|
||||
public string Build { get; init; } = UpgradeVersion.Current.FullVersion;
|
||||
|
||||
public string? CurrentProject { get; init; }
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
services.AddTelemetry(options =>
|
||||
{
|
||||
context.Configuration.GetSection("Telemetry").Bind(options);
|
||||
options.ProductVersion = Constants.FullVersion;
|
||||
options.ProductVersion = UpgradeVersion.Current.FullVersion;
|
||||
});
|
||||
|
||||
services.AddHostedService<ConsoleRunner>();
|
||||
|
@ -131,7 +131,7 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
.AddFromEnvironmentVariables(context.Configuration)
|
||||
.Configure(opts =>
|
||||
{
|
||||
opts.CurrentVersion = Constants.Version;
|
||||
opts.CurrentVersion = UpgradeVersion.Current.Version;
|
||||
|
||||
foreach (var path in options.Extension)
|
||||
{
|
||||
|
@ -197,7 +197,7 @@ namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
|||
|
||||
private static void ShowHeader()
|
||||
{
|
||||
var title = $"- Microsoft .NET Upgrade Assistant v{Constants.FullVersion} -";
|
||||
var title = $"- Microsoft .NET Upgrade Assistant v{UpgradeVersion.Current.FullVersion} -";
|
||||
Console.WriteLine(new string('-', title.Length));
|
||||
Console.WriteLine(title);
|
||||
Console.WriteLine(new string('-', title.Length));
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.DotNet.UpgradeAssistant.Cli
|
||||
{
|
||||
public class UpgradeVersion
|
||||
{
|
||||
public static UpgradeVersion Current { get; } = new();
|
||||
|
||||
public UpgradeVersion()
|
||||
{
|
||||
FullVersion = typeof(UpgradeVersion).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
|
||||
Version = ConvertToVersion(FullVersion);
|
||||
}
|
||||
|
||||
public string FullVersion { get; }
|
||||
|
||||
public Version Version { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Need to grab just the version part of strings such as: <c>0.2.231602+ef31c22633e629fac65d9f9d8bf700119c888380</c> and <c>0.2.0-dev</c>.
|
||||
/// </summary>
|
||||
/// <param name="version">An informational version string.</param>
|
||||
/// <returns>A version.</returns>
|
||||
private static Version ConvertToVersion(ReadOnlySpan<char> version)
|
||||
{
|
||||
var idx = version.IndexOfAny("+-");
|
||||
var newVersionString = idx > 0 ? version[..idx] : version;
|
||||
|
||||
return Version.Parse(newVersionString);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче