forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResolvedFile.cs
110 lines (96 loc) · 3.56 KB
/
ResolvedFile.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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 System.IO;
using System;
using NuGet.Packaging.Core;
using Microsoft.Build.Framework;
namespace Microsoft.NET.Build.Tasks
{
internal enum AssetType
{
None,
Runtime,
Native,
Resources,
PgoData
}
internal class ResolvedFile
{
public string SourcePath { get; }
public string PackageName { get; }
public string PackageVersion { get; }
public string PathInPackage { get; }
public string DestinationSubDirectory { get; }
public AssetType Asset{ get; }
public bool IsRuntimeTarget { get; }
public string RuntimeIdentifier { get; }
public string Culture { get; }
public string FileName
{
get { return Path.GetFileName(SourcePath); }
}
public string DestinationSubPath
{
get
{
return string.IsNullOrEmpty(DestinationSubDirectory) ?
FileName :
Path.Combine(DestinationSubDirectory, FileName);
}
}
public ResolvedFile(string sourcePath, string destinationSubDirectory, PackageIdentity package,
AssetType assetType = AssetType.None,
string pathInPackage = null)
{
SourcePath = Path.GetFullPath(sourcePath);
DestinationSubDirectory = destinationSubDirectory;
Asset = assetType;
PackageName = package.Id;
PackageVersion = package.Version.ToString();
PathInPackage = pathInPackage;
}
public ResolvedFile(ITaskItem item, bool isRuntimeTarget)
{
SourcePath = item.ItemSpec;
DestinationSubDirectory = item.GetMetadata(MetadataKeys.DestinationSubDirectory);
string assetType = item.GetMetadata(MetadataKeys.AssetType);
if (assetType.Equals("runtime", StringComparison.OrdinalIgnoreCase))
{
Asset = AssetType.Runtime;
}
else if (assetType.Equals("native", StringComparison.OrdinalIgnoreCase))
{
Asset = AssetType.Native;
}
else if (assetType.Equals("resources", StringComparison.OrdinalIgnoreCase))
{
Asset = AssetType.Resources;
}
else
{
throw new InvalidOperationException($"Unrecognized AssetType '{assetType}' for {SourcePath}");
}
PackageName = item.GetMetadata(MetadataKeys.NuGetPackageId);
PackageVersion = item.GetMetadata(MetadataKeys.NuGetPackageVersion);
PathInPackage = item.GetMetadata(MetadataKeys.PathInPackage);
RuntimeIdentifier = item.GetMetadata(MetadataKeys.RuntimeIdentifier);
Culture = item.GetMetadata(MetadataKeys.Culture);
IsRuntimeTarget = isRuntimeTarget;
}
public override bool Equals(object obj)
{
ResolvedFile other = obj as ResolvedFile;
return other != null &&
other.Asset == Asset &&
other.SourcePath == SourcePath &&
other.DestinationSubDirectory == DestinationSubDirectory;
}
public override int GetHashCode()
{
unchecked
{
return SourcePath.GetHashCode() + DestinationSubDirectory.GetHashCode();
}
}
}
}