-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathProjectPropertyHelpers.cs
More file actions
217 lines (186 loc) · 13.3 KB
/
Copy pathProjectPropertyHelpers.cs
File metadata and controls
217 lines (186 loc) · 13.3 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
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
// 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.Linq;
using Microsoft.Build.Construction;
using MSBuild.Conversion.Facts;
namespace MSBuild.Abstractions
{
/// <summary>
/// Helper functions for working with ProjectPropertyElements.
/// </summary>
public static class ProjectPropertyHelpers
{
/// <summary>
/// Checks if the given property is the 'Name' property, and if its value is the same as the project file name.
/// </summary>
public static bool IsNameDefault(ProjectPropertyElement prop, string projectName) =>
// TODO use: prop.ContainingProject ?
prop.ElementName.Equals(MSBuildFacts.NameNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(projectName, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if the given property is 'DefineConstants', and if the values defined are the defaults brought in by a template.
/// </summary>
public static bool IsDefineConstantDefault(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.DefineConstantsName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Split(';').All(constant => MSBuildFacts.DefaultDefineConstants.Contains(constant, StringComparer.OrdinalIgnoreCase));
/// <summary>
/// Checks if the given property is 'DebugType', and if the value defined is a default brought in by a template.
/// </summary>
public static bool IsDebugTypeDefault(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.DebugTypeName, StringComparison.OrdinalIgnoreCase)
&& MSBuildFacts.DefaultDebugTypes.Contains(prop.Value, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Checks if the given property is 'OutputPath', and if the value defined is a default brought in by a template.
/// </summary>
public static bool IsOutputPathDefault(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputPathName, StringComparison.OrdinalIgnoreCase)
&& MSBuildFacts.DefaultOutputPaths.Contains(prop.Value, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Checks if the given property is 'PlatformTarget', and if the value defined is a default brought in by a template.
/// </summary>
public static bool IsPlatformTargetDefault(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.PlatformTargetName, StringComparison.OrdinalIgnoreCase)
&& MSBuildFacts.DefaultPlatformTargets.Contains(prop.Value, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Checks if the given property is 'DocumentationFile', and if the value defined is a default brought in by a template.
/// </summary>
public static bool IsDocumentationFileDefault(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.DocumentationFileNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.DefaultDocumentationFileLocation, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if a property is any of the unencessary test properties. This is only good to do <em>after</em> the loading phase where we discard inapplicable test projects.
/// </summary>
public static bool IsUnnecessaryTestProperty(ProjectPropertyElement prop) =>
IsUITestExtensionsPackagesReferencePath(prop) ||
prop.ElementName.Equals(MSTestFacts.IsCodedUITestNodeName, StringComparison.OrdinalIgnoreCase) ||
prop.ElementName.Equals(MSTestFacts.TestProjectTypeNodeName, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if a property is the old NuGetPackageImportStamp property that used to be for some reason starting with VS 2013, but seems to no longer be required, but is still<em>stamped</em>(har har har...) into test project files and maybe others (lol).
/// </summary>
public static bool IsEmptyNuGetPackageImportStamp(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.NuGetPackageImportStampNodeName, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if a property is a default ReferencePath property that MSTest stamps into the project file.
/// </summary>
public static bool IsUITestExtensionsPackagesReferencePath(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.ReferencePathNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.ContainsIgnoreCase(MSTestFacts.UITestExtensionPackagesReferencePathFileName);
public static bool IsOutputTypeNode(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Determines if the name and value of two properties are identical.
/// </summary>
public static bool ArePropertiesEqual(ProjectPropertyElement a, ProjectPropertyElement b) =>
a.ElementName.Equals(b.ElementName, StringComparison.OrdinalIgnoreCase)
&& a.Value.Equals(b.Value, StringComparison.OrdinalIgnoreCase)
&& a.Condition.Equals(b.Condition, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if a property is '.<ProjectTypeGuids>'
/// </summary>
public static bool IsProjectTypeGuidsNode(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.ProjectTypeGuidsNodeName, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Determines if a property lists the default project type GUIds for legacy web projects.
/// </summary>
public static bool IsLegacyWebProjectTypeGuidsProperty(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => WebFacts.LegacyWebProjectTypeGuids.Contains(Guid.Parse(guidString)));
/// <summary>
/// Checks if a given OutputType node is wither a library, exe, or WinExe.
/// </summary>
public static bool IsSupportedOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& (prop.Value.Equals(MSBuildFacts.LibraryOutputType, StringComparison.OrdinalIgnoreCase)
|| prop.Value.Equals(MSBuildFacts.ExeOutputType, StringComparison.OrdinalIgnoreCase)
|| prop.Value.Equals(MSBuildFacts.WinExeOutputType, StringComparison.OrdinalIgnoreCase));
/// <summary>
/// Checks if a given property defines project type guids for C#, VB.NET, or F#.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if all types are language project types, false otherwise.</returns>
public static bool AllProjectTypeGuidsAreLanguageProjectTypeGuids(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').All(guidString => MSBuildFacts.LanguageProjectTypeGuids.Contains(Guid.Parse(guidString)));
/// <summary>
/// Checks if all projecttypeguids specified are known desktop project type guids.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if all types are desktop project types, false otherwise.</returns>
public static bool AllProjectTypeGuidsAreDesktopProjectTypeGuids(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').All(guidString => DesktopFacts.KnownSupportedDesktopProjectTypeGuids.Contains(Guid.Parse(guidString)));
/// <summary>
/// Checks if all projecttypeguids specified are known desktop project type guids.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if all types are legacy test types, false otherwise.</returns>
public static bool AllProjectTypeGuidsAreLegacyTestProjectTypeGuids(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').All(guidString => MSTestFacts.KnownOldMSTestProjectTypeGuids.Contains(Guid.Parse(guidString)));
/// <summary>
/// Checks if a given property specifies IsCodedUITest=True, which is not only unsupported for .NET Core but is also deprecated after VS 2019.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates a Coded UI test, false otherwise.</returns>
public static bool IsCodedUITest(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSTestFacts.IsCodedUITestNodeName, StringComparison.OrdinalIgnoreCase) && prop.Value.Equals("True", StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if a test property is TestProjectType=UnitTest.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates a unit test, false otherwise.</returns>
public static bool IsUnitTestType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSTestFacts.TestProjectTypeNodeName, StringComparison.OrdinalIgnoreCase) && prop.Value.Equals(MSTestFacts.UnitTestTestProjectType, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if an OutputType node is Library.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates a library output type, false otherwise.</returns>
public static bool IsLibraryOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.LibraryOutputType, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if an OutputType node is Exe.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates an executable, false otherwise.</returns>
public static bool IsExeOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.ExeOutputType, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if an OutputType node is AppContainerExe.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates an app container executable, false otherwise.</returns>
public static bool IsAppContainerExeOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.AppContainerExeOutputType, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if an OutputType node is Exe.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if property indicates a windows executable, false otherwise.</returns>
public static bool IsWinExeOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.WinExeOutputType, StringComparison.OrdinalIgnoreCase);
/// <summary>
/// Checks if an OutputType node is WinMdObj.
/// </summary>
public static bool IsWinMdObjProjectType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.WinMdObjOutputType, StringComparison.OrdinalIgnoreCase);
public static bool IsVisualBasicProject(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => Guid.Parse(guidString) == MSBuildFacts.LanguageProjectTypeVisualBasic);
/// <summary>
/// Determines if a property lists the default project type GUId for Xamarin.Android.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if any property indicates a Xamarin Android project, false otherwise.</returns>
public static bool IsXamarinDroidProjectTypeGuidsProperty(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => XamarinFacts.XamarinDroidProjectTypeGuids.Contains(Guid.Parse(guidString)));
/// <summary>
/// Determines if a property lists the default project type GUId for Xamarin.iOS projects.
/// </summary>
/// <param name="prop">Element to analyze for type.</param>
/// <returns>True if any property indicate a Xamarin IOS project, false otherwise.</returns>
public static bool IsXamariniOSProjectTypeGuidsProperty(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => XamarinFacts.XamariniOSProjectTypeGuids.Contains(Guid.Parse(guidString)));
}
}