forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemUtilities.NuGet.cs
33 lines (28 loc) · 1.14 KB
/
ItemUtilities.NuGet.cs
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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using NuGet.Packaging.Core;
using NuGet.Versioning;
namespace Microsoft.NET.Build.Tasks
{
internal static partial class ItemUtilities
{
public static PackageIdentity GetPackageIdentity(ITaskItem item)
{
string packageName = item.GetMetadata(MetadataKeys.PackageName);
string packageVersion = item.GetMetadata(MetadataKeys.PackageVersion);
if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(packageVersion))
{
packageName = item.GetMetadata(MetadataKeys.NuGetPackageId);
packageVersion = item.GetMetadata(MetadataKeys.NuGetPackageVersion);
}
if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(packageVersion))
{
return null;
}
return new PackageIdentity(
packageName,
NuGetVersion.Parse(packageVersion));
}
}
}