-
Notifications
You must be signed in to change notification settings - Fork 692
/
ProjectRestoreMetadata.cs
287 lines (247 loc) · 13.2 KB
/
ProjectRestoreMetadata.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// 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 System.Collections.Generic;
using System.Linq;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Shared;
using NuGet.Versioning;
namespace NuGet.ProjectModel
{
public class ProjectRestoreMetadata : IEquatable<ProjectRestoreMetadata>
{
/// <summary>
/// Restore behavior type.
/// </summary>
public ProjectStyle ProjectStyle { get; set; } = ProjectStyle.Unknown;
/// <summary>
/// MSBuild project file path.
/// </summary>
public string ProjectPath { get; set; }
/// <summary>
/// Full path to the project.json file if it exists.
/// </summary>
public string ProjectJsonPath { get; set; }
/// <summary>
/// Assets file output path.
/// </summary>
public string OutputPath { get; set; }
/// <summary>
/// Friendly project name.
/// </summary>
public string ProjectName { get; set; }
/// <summary>
/// Name unique to the project across the solution.
/// </summary>
public string ProjectUniqueName { get; set; }
/// <summary>
/// Package feed sources.
/// </summary>
public IList<PackageSource> Sources { get; set; } = new List<PackageSource>();
/// <summary>
/// User packages folder path.
/// </summary>
public string PackagesPath { get; set; }
/// <summary>
/// Cache file path
/// </summary>
public string CacheFilePath { get; set; }
/// <summary>
/// Fallback folders.
/// </summary>
public IList<string> FallbackFolders { get; set; } = new List<string>();
/// <summary>
/// ConfigFilePaths used.
/// </summary>
public IList<string> ConfigFilePaths { get; set; } = new List<string>();
/// <summary>
/// Framework specific metadata, this may be a subset of the project's frameworks.
/// Operations to determine the nearest framework should be done against the project's frameworks,
/// and then matched directly to this section.
/// </summary>
public IList<ProjectRestoreMetadataFrameworkInfo> TargetFrameworks { get; set; } = new List<ProjectRestoreMetadataFrameworkInfo>();
/// <summary>
/// Original target frameworks strings. These are used to match msbuild conditionals to $(TargetFramework)
/// </summary>
public IList<string> OriginalTargetFrameworks { get; set; } = new List<string>();
/// <summary>
/// True if $(TargetFrameworks) is used and the build is using Cross Targeting.
/// </summary>
public bool CrossTargeting { get; set; }
/// <summary>
/// Whether or not to restore the packages directory using the legacy format, which write original case paths
/// instead of lowercase.
/// </summary>
public bool LegacyPackagesDirectory { get; set; }
/// <summary>
/// Asset files. These should be equivalent to the files that would be
/// in the nupkg after packing the project.
/// </summary>
public IList<ProjectRestoreMetadataFile> Files { get; set; } = new List<ProjectRestoreMetadataFile>();
/// <summary>
/// Compatibility check for runtime framework assets.
/// </summary>
public bool ValidateRuntimeAssets { get; set; }
/// <summary>
/// True if this is a Legacy Package Reference project
/// </summary>
public bool SkipContentFileWrite { get; set; }
/// <summary>
/// Contains Project wide properties for Warnings.
/// </summary>
public WarningProperties ProjectWideWarningProperties { get; set; } = new WarningProperties();
public RestoreLockProperties RestoreLockProperties { get; set; } = new RestoreLockProperties();
/// <summary>
/// Gets or sets a value indicating whether or not central package management is enabled.
/// </summary>
public bool CentralPackageVersionsEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not a package version specified centrally can be overridden.
/// </summary>
public bool CentralPackageVersionOverrideDisabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not floating versions are allowed when using central package management (CPM).
/// </summary>
public bool CentralPackageFloatingVersionsEnabled { get; set; }
public bool CentralPackageTransitivePinningEnabled { get; set; }
public RestoreAuditProperties RestoreAuditProperties { get; set; }
/// <summary>
/// A unified flag to help users manage their SDK warning levels. Example: 9.0.100.
/// When introducing a new warning or error use this property to
/// allow users to tell the sdk "treat me as if I were SDK x.y.z" and manage breaking changes
/// </summary>
public NuGetVersion SdkAnalysisLevel { get; set; }
/// <summary>
/// Indicates that Microsoft.NET.Sdk is being used.
/// </summary>
public bool UsingMicrosoftNETSdk { get; set; }
public bool UseLegacyDependencyResolver { get; set; }
public override int GetHashCode()
{
StringComparer osStringComparer = PathUtility.GetStringComparerBasedOnOS();
var hashCode = new HashCodeCombiner();
hashCode.AddStruct(ProjectStyle);
hashCode.AddObject(ProjectPath, osStringComparer);
hashCode.AddObject(ProjectJsonPath, osStringComparer);
hashCode.AddObject(OutputPath, osStringComparer);
hashCode.AddObject(ProjectName, osStringComparer);
hashCode.AddObject(ProjectUniqueName, osStringComparer);
hashCode.AddUnorderedSequence(Sources);
hashCode.AddObject(PackagesPath, osStringComparer);
hashCode.AddUnorderedSequence(ConfigFilePaths, osStringComparer);
hashCode.AddUnorderedSequence(FallbackFolders, osStringComparer);
hashCode.AddUnorderedSequence(TargetFrameworks);
hashCode.AddUnorderedSequence(OriginalTargetFrameworks, StringComparer.OrdinalIgnoreCase);
hashCode.AddObject(CrossTargeting);
hashCode.AddObject(LegacyPackagesDirectory);
hashCode.AddSequence(Files);
hashCode.AddObject(ValidateRuntimeAssets);
hashCode.AddObject(SkipContentFileWrite);
hashCode.AddObject(ProjectWideWarningProperties);
hashCode.AddObject(RestoreLockProperties);
hashCode.AddObject(CentralPackageVersionsEnabled);
hashCode.AddObject(CentralPackageFloatingVersionsEnabled);
hashCode.AddObject(CentralPackageVersionOverrideDisabled);
hashCode.AddObject(CentralPackageTransitivePinningEnabled);
hashCode.AddObject(RestoreAuditProperties);
hashCode.AddObject(UsingMicrosoftNETSdk);
hashCode.AddObject(SdkAnalysisLevel);
hashCode.AddObject(UseLegacyDependencyResolver);
return hashCode.CombinedHash;
}
public override bool Equals(object obj)
{
return Equals(obj as ProjectRestoreMetadata);
}
public bool Equals(ProjectRestoreMetadata other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
StringComparer osStringComparer = PathUtility.GetStringComparerBasedOnOS();
return ProjectStyle == other.ProjectStyle &&
osStringComparer.Equals(ProjectPath, other.ProjectPath) &&
osStringComparer.Equals(ProjectJsonPath, other.ProjectJsonPath) &&
osStringComparer.Equals(OutputPath, other.OutputPath) &&
osStringComparer.Equals(ProjectName, other.ProjectName) &&
osStringComparer.Equals(ProjectUniqueName, other.ProjectUniqueName) &&
GetSources(Sources).SetEqualsWithNullCheck(GetSources(other.Sources), StringComparer.OrdinalIgnoreCase) &&
osStringComparer.Equals(PackagesPath, other.PackagesPath) &&
ConfigFilePaths.OrderedEquals(other.ConfigFilePaths, filePath => filePath, osStringComparer, osStringComparer) &&
FallbackFolders.OrderedEquals(other.FallbackFolders, fallbackFolder => fallbackFolder, osStringComparer, osStringComparer) &&
EqualityUtility.OrderedEquals(TargetFrameworks, other.TargetFrameworks, dep => dep.TargetAlias, StringComparer.OrdinalIgnoreCase) &&
OriginalTargetFrameworks.OrderedEquals(other.OriginalTargetFrameworks, fw => fw, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) &&
CrossTargeting == other.CrossTargeting &&
LegacyPackagesDirectory == other.LegacyPackagesDirectory &&
ValidateRuntimeAssets == other.ValidateRuntimeAssets &&
SkipContentFileWrite == other.SkipContentFileWrite &&
EqualityUtility.SequenceEqualWithNullCheck(Files, other.Files) &&
EqualityUtility.EqualsWithNullCheck(ProjectWideWarningProperties, other.ProjectWideWarningProperties) &&
EqualityUtility.EqualsWithNullCheck(RestoreLockProperties, other.RestoreLockProperties) &&
EqualityUtility.EqualsWithNullCheck(CentralPackageVersionsEnabled, other.CentralPackageVersionsEnabled) &&
EqualityUtility.EqualsWithNullCheck(CentralPackageFloatingVersionsEnabled, other.CentralPackageFloatingVersionsEnabled) &&
EqualityUtility.EqualsWithNullCheck(CentralPackageVersionOverrideDisabled, other.CentralPackageVersionOverrideDisabled) &&
EqualityUtility.EqualsWithNullCheck(CentralPackageTransitivePinningEnabled, other.CentralPackageTransitivePinningEnabled) &&
RestoreAuditProperties == other.RestoreAuditProperties &&
UsingMicrosoftNETSdk == other.UsingMicrosoftNETSdk &&
EqualityUtility.EqualsWithNullCheck(SdkAnalysisLevel, other.SdkAnalysisLevel) &&
UseLegacyDependencyResolver == other.UseLegacyDependencyResolver;
}
private HashSet<string> GetSources(IList<PackageSource> sources)
{
#if NETSTANDARD2_0
var setSources = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
#else
var setSources = new HashSet<string>(sources.Count, StringComparer.OrdinalIgnoreCase);
#endif
for (var i = 0; i < sources.Count; i++)
{
setSources.Add(sources[i].Source);
}
return setSources;
}
public virtual ProjectRestoreMetadata Clone()
{
var clone = new ProjectRestoreMetadata();
FillClone(clone);
return clone;
}
protected void FillClone(ProjectRestoreMetadata clone)
{
clone.ProjectStyle = ProjectStyle;
clone.ProjectPath = ProjectPath;
clone.ProjectJsonPath = ProjectJsonPath;
clone.OutputPath = OutputPath;
clone.ProjectName = ProjectName;
clone.ProjectUniqueName = ProjectUniqueName;
clone.PackagesPath = PackagesPath;
clone.CacheFilePath = CacheFilePath;
clone.CrossTargeting = CrossTargeting;
clone.LegacyPackagesDirectory = LegacyPackagesDirectory;
clone.SkipContentFileWrite = SkipContentFileWrite;
clone.ValidateRuntimeAssets = ValidateRuntimeAssets;
clone.FallbackFolders = FallbackFolders != null ? new List<string>(FallbackFolders) : null;
clone.ConfigFilePaths = ConfigFilePaths != null ? new List<string>(ConfigFilePaths) : null;
clone.OriginalTargetFrameworks = OriginalTargetFrameworks != null ? new List<string>(OriginalTargetFrameworks) : null;
clone.Sources = Sources?.Select(c => c.Clone()).ToList();
clone.TargetFrameworks = TargetFrameworks?.Select(c => c.Clone()).ToList();
clone.Files = Files?.Select(c => c.Clone()).ToList();
clone.ProjectWideWarningProperties = ProjectWideWarningProperties?.Clone();
clone.RestoreLockProperties = RestoreLockProperties?.Clone();
clone.CentralPackageVersionsEnabled = CentralPackageVersionsEnabled;
clone.CentralPackageFloatingVersionsEnabled = CentralPackageFloatingVersionsEnabled;
clone.CentralPackageVersionOverrideDisabled = CentralPackageVersionOverrideDisabled;
clone.CentralPackageTransitivePinningEnabled = CentralPackageTransitivePinningEnabled;
clone.RestoreAuditProperties = RestoreAuditProperties?.Clone();
clone.SdkAnalysisLevel = SdkAnalysisLevel;
clone.UsingMicrosoftNETSdk = UsingMicrosoftNETSdk;
clone.UseLegacyDependencyResolver = UseLegacyDependencyResolver;
}
}
}