-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathNuGetVersionUtility.cs
More file actions
44 lines (37 loc) · 1.34 KB
/
NuGetVersionUtility.cs
File metadata and controls
44 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using NuGet.Versioning;
namespace NuGet.Services.Metadata.Catalog.Helpers
{
public static class NuGetVersionUtility
{
public static string NormalizeVersion(string version)
{
NuGetVersion parsedVersion;
if (!NuGetVersion.TryParse(version, out parsedVersion))
{
throw new InvalidOperationException($"Invalid version found when normalized: '{version}'");
}
return parsedVersion.ToNormalizedString();
}
public static string NormalizeVersionRange(string versionRange, string defaultValue)
{
VersionRange parsedVersionRange;
if (!VersionRange.TryParse(versionRange, out parsedVersionRange))
{
return defaultValue;
}
return parsedVersionRange.ToNormalizedString();
}
public static string GetFullVersionString(string version)
{
NuGetVersion parsedVersion;
if (!NuGetVersion.TryParse(version, out parsedVersion))
{
return version;
}
return parsedVersion.ToFullString();
}
}
}