-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathBuildRequestData.cs
More file actions
244 lines (208 loc) · 13 KB
/
Copy pathBuildRequestData.cs
File metadata and controls
244 lines (208 loc) · 13 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
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
// 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.Collections.Generic;
using Microsoft.Build.Collections;
using Microsoft.Build.Experimental.BuildCheck;
using Microsoft.Build.Framework;
namespace Microsoft.Build.Execution
{
/// <summary>
/// BuildRequestData encapsulates all the data needed to submit a build request.
/// </summary>
public class BuildRequestData : BuildRequestData<BuildRequestData, BuildResult>
{
/// <summary>
/// Constructs a BuildRequestData for build requests based on project instances.
/// </summary>
/// <param name="projectInstance">The instance to build.</param>
/// <param name="targetsToBuild">The targets to build.</param>
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild)
: this(projectInstance, targetsToBuild, null, BuildRequestDataFlags.None)
{
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project instances.
/// </summary>
/// <param name="projectInstance">The instance to build.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use, if any. May be null.</param>
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices)
: this(projectInstance, targetsToBuild, hostServices, BuildRequestDataFlags.None)
{
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project instances.
/// </summary>
/// <param name="projectInstance">The instance to build.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use, if any. May be null.</param>
/// <param name="flags">Flags controlling this build request.</param>
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags)
: this(projectInstance, targetsToBuild, hostServices, flags, null)
{
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project instances.
/// </summary>
/// <param name="projectInstance">The instance to build.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use, if any. May be null.</param>
/// <param name="flags">Flags controlling this build request.</param>
/// <param name="propertiesToTransfer">The list of properties whose values should be transferred from the project to any out-of-proc node.</param>
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer)
: this(targetsToBuild, hostServices, flags, projectInstance.FullPath)
{
ArgumentNullException.ThrowIfNull(projectInstance);
if (projectInstance.EvaluationStage != Evaluation.ProjectEvaluationStage.Full)
{
Shared.ErrorUtilities.ThrowInvalidOperation("OM_PartialEvaluationCannotBuild", projectInstance.EvaluationStage);
}
foreach (string targetName in targetsToBuild)
{
ArgumentNullException.ThrowIfNull(targetName, "target");
}
ProjectInstance = projectInstance;
GlobalPropertiesDictionary = projectInstance.GlobalPropertiesDictionary;
ExplicitlySpecifiedToolsVersion = projectInstance.ExplicitToolsVersion;
if (propertiesToTransfer != null)
{
PropertiesToTransfer = new List<string>(propertiesToTransfer);
}
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project instances.
/// </summary>
/// <param name="projectInstance">The instance to build.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use, if any. May be null.</param>
/// <param name="flags">Flags controlling this build request.</param>
/// <param name="propertiesToTransfer">The list of properties whose values should be transferred from the project to any out-of-proc node.</param>
/// <param name="requestedProjectState">A <see cref="Execution.RequestedProjectState"/> describing properties, items, and metadata that should be returned. Requires setting <see cref="BuildRequestDataFlags.ProvideSubsetOfStateAfterBuild"/>.</param>
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer, RequestedProjectState requestedProjectState)
: this(projectInstance, targetsToBuild, hostServices, flags, propertiesToTransfer)
{
ArgumentNullException.ThrowIfNull(requestedProjectState);
RequestedProjectState = requestedProjectState;
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project files.
/// </summary>
/// <param name="projectFullPath">The full path to the project file.</param>
/// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param>
/// <param name="toolsVersion">The tools version to use for the build. May be null.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use. May be null.</param>
public BuildRequestData(string projectFullPath, IDictionary<string, string?> globalProperties, string? toolsVersion, string[] targetsToBuild, HostServices? hostServices)
: this(projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, BuildRequestDataFlags.None)
{
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project files.
/// </summary>
/// <param name="projectFullPath">The full path to the project file.</param>
/// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param>
/// <param name="toolsVersion">The tools version to use for the build. May be null.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use. May be null.</param>
/// <param name="flags">The <see cref="BuildRequestDataFlags"/> to use.</param>
/// <param name="requestedProjectState">A <see cref="Execution.RequestedProjectState"/> describing properties, items, and metadata that should be returned. Requires setting <see cref="BuildRequestDataFlags.ProvideSubsetOfStateAfterBuild"/>.</param>
public BuildRequestData(string projectFullPath, IDictionary<string, string?> globalProperties,
string? toolsVersion, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags,
RequestedProjectState requestedProjectState)
: this(projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, flags)
{
ArgumentNullException.ThrowIfNull(requestedProjectState);
RequestedProjectState = requestedProjectState;
}
/// <summary>
/// Constructs a BuildRequestData for build requests based on project files.
/// </summary>
/// <param name="projectFullPath">The full path to the project file.</param>
/// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param>
/// <param name="toolsVersion">The tools version to use for the build. May be null.</param>
/// <param name="targetsToBuild">The targets to build.</param>
/// <param name="hostServices">The host services to use. May be null.</param>
/// <param name="flags">The <see cref="BuildRequestDataFlags"/> to use.</param>
public BuildRequestData(string projectFullPath, IDictionary<string, string?> globalProperties, string? toolsVersion, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags)
: this(targetsToBuild, hostServices, flags, FileUtilities.NormalizePath(projectFullPath)!)
{
ArgumentException.ThrowIfNullOrEmpty(projectFullPath);
ArgumentNullException.ThrowIfNull(globalProperties);
GlobalPropertiesDictionary = new PropertyDictionary<ProjectPropertyInstance>(globalProperties.Count);
foreach (KeyValuePair<string, string?> propertyPair in globalProperties)
{
GlobalPropertiesDictionary.Set(ProjectPropertyInstance.Create(propertyPair.Key, propertyPair.Value));
}
ExplicitlySpecifiedToolsVersion = toolsVersion;
}
/// <summary>
/// Common constructor.
/// </summary>
private BuildRequestData(string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, string projectFullPath)
: base(targetsToBuild, flags, hostServices)
{
ProjectFullPath = projectFullPath;
}
/// <summary>
/// The actual project, in the case where the project doesn't come from disk.
/// May be null.
/// </summary>
/// <value>The project instance.</value>
public ProjectInstance? ProjectInstance
{
get;
}
/// <summary>The project file.</summary>
/// <value>The project file to be built.</value>
public string ProjectFullPath { get; internal set; }
internal override BuildSubmissionBase<BuildRequestData, BuildResult> CreateSubmission(BuildManager buildManager,
int submissionId, BuildRequestData requestData,
bool legacyThreadingSemantics) =>
new BuildSubmission(buildManager, submissionId, requestData, legacyThreadingSemantics);
public override IEnumerable<string> EntryProjectsFullPath => ProjectFullPath.AsSingleItemEnumerable();
/// <summary>
/// The global properties to use.
/// </summary>
/// <value>The set of global properties to be used to build this request.</value>
public ICollection<ProjectPropertyInstance> GlobalProperties => (GlobalPropertiesDictionary == null) ?
(ICollection<ProjectPropertyInstance>)ReadOnlyEmptyCollection<ProjectPropertyInstance>.Instance :
new ReadOnlyCollection<ProjectPropertyInstance>(GlobalPropertiesDictionary);
public override bool IsGraphRequest => false;
/// <summary>
/// The explicitly requested tools version to use.
/// </summary>
public string? ExplicitlySpecifiedToolsVersion { get; }
/// <summary>
/// Returns a list of properties to transfer out of proc for the build.
/// </summary>
public IEnumerable<string>? PropertiesToTransfer { get; }
/// <summary>
/// Returns the properties, items, and metadata that will be returned
/// by this build.
/// </summary>
public RequestedProjectState? RequestedProjectState { get; }
/// <summary>
/// Whether the tools version used originated from an explicit specification,
/// for example from an MSBuild task or /tv switch.
/// </summary>
internal bool ExplicitToolsVersionSpecified => ExplicitlySpecifiedToolsVersion != null;
/// <summary>
/// Returns the global properties as a dictionary.
/// </summary>
internal PropertyDictionary<ProjectPropertyInstance>? GlobalPropertiesDictionary { get; }
private IReadOnlyDictionary<string, string?>? _globalPropertiesLookup;
/// <inheritdoc cref="BuildRequestDataBase"/>
public override IReadOnlyDictionary<string, string?> GlobalPropertiesLookup => _globalPropertiesLookup ??=
Execution.GlobalPropertiesLookup.ToGlobalPropertiesLookup(GlobalPropertiesDictionary);
// WARNING!: Do not remove the below proxy properties.
// They are required to make the OM forward compatible
// (code built against this OM should run against binaries with previous version of OM).
/// <inheritdoc cref="BuildRequestDataBase.TargetNames"/>
public new ICollection<string> TargetNames => base.TargetNames;
/// <inheritdoc cref="BuildRequestDataBase.Flags"/>
public new BuildRequestDataFlags Flags => base.Flags;
/// <inheritdoc cref="BuildRequestDataBase.HostServices"/>
public new HostServices? HostServices => base.HostServices;
}
}