@@ -12,11 +12,24 @@ namespace Microsoft.DotNet.Cli.Utils;
12
12
/// </summary>
13
13
public sealed class MSBuildArgs
14
14
{
15
- private MSBuildArgs ( ReadOnlyDictionary < string , string > ? properties , ReadOnlyDictionary < string , string > ? restoreProperties , string [ ] ? targets , VerbosityOptions ? verbosity , string [ ] ? otherMSBuildArgs )
15
+ private MSBuildArgs (
16
+ ReadOnlyDictionary < string , string > ? properties ,
17
+ ReadOnlyDictionary < string , string > ? restoreProperties ,
18
+ string [ ] ? targets ,
19
+ string [ ] ? getProperty ,
20
+ string [ ] ? getItem ,
21
+ string [ ] ? getTargetResult ,
22
+ string [ ] ? getResultOutputFile ,
23
+ VerbosityOptions ? verbosity ,
24
+ string [ ] ? otherMSBuildArgs )
16
25
{
17
26
GlobalProperties = properties ;
18
27
RestoreGlobalProperties = restoreProperties ;
19
28
RequestedTargets = targets ;
29
+ GetProperty = getProperty ;
30
+ GetItem = getItem ;
31
+ GetTargetResult = getTargetResult ;
32
+ GetResultOutputFile = getResultOutputFile ;
20
33
Verbosity = verbosity ;
21
34
OtherMSBuildArgs = otherMSBuildArgs is not null
22
35
? [ .. otherMSBuildArgs ]
@@ -37,6 +50,15 @@ private MSBuildArgs(ReadOnlyDictionary<string, string>? properties, ReadOnlyDict
37
50
/// The ordered list of targets that should be passed to MSBuild.
38
51
/// </summary>
39
52
public string [ ] ? RequestedTargets { get ; }
53
+
54
+ public string [ ] ? GetProperty { get ; }
55
+
56
+ public string [ ] ? GetItem { get ; }
57
+
58
+ public string [ ] ? GetTargetResult { get ; }
59
+
60
+ public string [ ] ? GetResultOutputFile { get ; }
61
+
40
62
public VerbosityOptions ? Verbosity { get ; }
41
63
42
64
/// <summary>
@@ -70,6 +92,10 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
70
92
var globalProperties = parseResult . GetResult ( "--property" ) is OptionResult propResult ? propResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
71
93
var restoreProperties = parseResult . GetResult ( "--restoreProperty" ) is OptionResult restoreResult ? restoreResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
72
94
var requestedTargets = parseResult . GetResult ( "--target" ) is OptionResult targetResult ? targetResult . GetValueOrDefault < string [ ] ? > ( ) : null ;
95
+ var getProperty = TryGetValue < string [ ] > ( "--getProperty" ) ;
96
+ var getItem = TryGetValue < string [ ] ? > ( "--getItem" ) ;
97
+ var getTargetResult = TryGetValue < string [ ] ? > ( "--getTargetResult" ) ;
98
+ var getResultOutputFile = TryGetValue < string [ ] ? > ( "--getResultOutputFile" ) ;
73
99
var verbosity = parseResult . GetResult ( "--verbosity" ) is OptionResult verbosityResult
74
100
? verbosityResult . GetValueOrDefault < VerbosityOptions ? > ( )
75
101
: null ;
@@ -78,26 +104,35 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
78
104
properties : globalProperties ,
79
105
restoreProperties : restoreProperties ,
80
106
targets : requestedTargets ,
107
+ getProperty : getProperty ,
108
+ getItem : getItem ,
109
+ getTargetResult : getTargetResult ,
110
+ getResultOutputFile : getResultOutputFile ,
81
111
otherMSBuildArgs : otherMSBuildArgs ,
82
112
verbosity : verbosity ) ;
113
+
114
+ T ? TryGetValue < T > ( string name )
115
+ {
116
+ return options . Any ( o => o . Name == name ) ? parseResult . GetValue < T > ( name ) : default ;
117
+ }
83
118
}
84
119
85
120
86
121
public static MSBuildArgs FromProperties ( ReadOnlyDictionary < string , string > ? properties )
87
122
{
88
- return new MSBuildArgs ( properties , null , null , null , null ) ;
123
+ return new MSBuildArgs ( properties , null , null , null , null , null , null , null , null ) ;
89
124
}
90
125
91
126
public static MSBuildArgs FromOtherArgs ( params ReadOnlySpan < string > args )
92
127
{
93
- return new MSBuildArgs ( null , null , null , null , args . ToArray ( ) ) ;
128
+ return new MSBuildArgs ( null , null , null , null , null , null , null , null , args . ToArray ( ) ) ;
94
129
}
95
130
public static MSBuildArgs FromVerbosity ( VerbosityOptions verbosity )
96
131
{
97
- return new MSBuildArgs ( null , null , null , verbosity , null ) ;
132
+ return new MSBuildArgs ( null , null , null , null , null , null , null , verbosity , null ) ;
98
133
}
99
134
100
- public static readonly MSBuildArgs ForHelp = new ( null , null , null , null , [ "--help" ] ) ;
135
+ public static readonly MSBuildArgs ForHelp = new ( null , null , null , null , null , null , null , null , [ "--help" ] ) ;
101
136
102
137
/// <summary>
103
138
/// Completely replaces the MSBuild arguments with the provided <paramref name="newArgs"/>.
@@ -108,6 +143,10 @@ public MSBuildArgs CloneWithExplicitArgs(string[] newArgs)
108
143
properties : GlobalProperties ,
109
144
restoreProperties : RestoreGlobalProperties ,
110
145
targets : RequestedTargets ,
146
+ getProperty : GetProperty ,
147
+ getItem : GetItem ,
148
+ getTargetResult : GetTargetResult ,
149
+ getResultOutputFile : GetResultOutputFile ,
111
150
otherMSBuildArgs : newArgs ,
112
151
verbosity : Verbosity ) ;
113
152
}
@@ -120,63 +159,153 @@ public MSBuildArgs CloneWithAdditionalArgs(params string[] additionalArgs)
120
159
if ( additionalArgs is null || additionalArgs . Length == 0 )
121
160
{
122
161
// If there are no additional args, we can just return the current instance.
123
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
162
+ return new MSBuildArgs (
163
+ GlobalProperties ,
164
+ RestoreGlobalProperties ,
165
+ RequestedTargets ,
166
+ GetProperty ,
167
+ GetItem ,
168
+ GetTargetResult ,
169
+ GetResultOutputFile ,
170
+ Verbosity ,
171
+ OtherMSBuildArgs . ToArray ( ) ) ;
124
172
}
125
173
126
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
174
+ return new MSBuildArgs (
175
+ GlobalProperties ,
176
+ RestoreGlobalProperties ,
177
+ RequestedTargets ,
178
+ GetProperty ,
179
+ GetItem ,
180
+ GetTargetResult ,
181
+ GetResultOutputFile ,
182
+ Verbosity ,
183
+ [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
127
184
}
128
185
129
186
public MSBuildArgs CloneWithAdditionalRestoreProperties ( ReadOnlyDictionary < string , string > ? additionalRestoreProperties )
130
187
{
131
188
if ( additionalRestoreProperties is null || additionalRestoreProperties . Count == 0 )
132
189
{
133
190
// If there are no additional restore properties, we can just return the current instance.
134
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
191
+ return new MSBuildArgs (
192
+ GlobalProperties ,
193
+ RestoreGlobalProperties ,
194
+ RequestedTargets ,
195
+ GetProperty ,
196
+ GetItem ,
197
+ GetTargetResult ,
198
+ GetResultOutputFile ,
199
+ Verbosity ,
200
+ OtherMSBuildArgs . ToArray ( ) ) ;
135
201
}
136
202
if ( RestoreGlobalProperties is null )
137
203
{
138
- return new MSBuildArgs ( GlobalProperties , additionalRestoreProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
204
+ return new MSBuildArgs (
205
+ GlobalProperties ,
206
+ additionalRestoreProperties ,
207
+ RequestedTargets ,
208
+ GetProperty ,
209
+ GetItem ,
210
+ GetTargetResult ,
211
+ GetResultOutputFile ,
212
+ Verbosity ,
213
+ OtherMSBuildArgs . ToArray ( ) ) ;
139
214
}
140
215
141
216
var newRestoreProperties = new Dictionary < string , string > ( RestoreGlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
142
217
foreach ( var kvp in additionalRestoreProperties )
143
218
{
144
219
newRestoreProperties [ kvp . Key ] = kvp . Value ;
145
220
}
146
- return new MSBuildArgs ( GlobalProperties , new ( newRestoreProperties ) , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
221
+ return new MSBuildArgs (
222
+ GlobalProperties ,
223
+ new ( newRestoreProperties ) ,
224
+ RequestedTargets ,
225
+ GetProperty ,
226
+ GetItem ,
227
+ GetTargetResult ,
228
+ GetResultOutputFile ,
229
+ Verbosity ,
230
+ OtherMSBuildArgs . ToArray ( ) ) ;
147
231
}
148
232
149
233
public MSBuildArgs CloneWithAdditionalProperties ( ReadOnlyDictionary < string , string > ? additionalProperties )
150
234
{
151
235
if ( additionalProperties is null || additionalProperties . Count == 0 )
152
236
{
153
237
// If there are no additional properties, we can just return the current instance.
154
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
238
+ return new MSBuildArgs (
239
+ GlobalProperties ,
240
+ RestoreGlobalProperties ,
241
+ RequestedTargets ,
242
+ GetProperty ,
243
+ GetItem ,
244
+ GetTargetResult ,
245
+ GetResultOutputFile ,
246
+ Verbosity ,
247
+ OtherMSBuildArgs . ToArray ( ) ) ;
155
248
}
156
249
if ( GlobalProperties is null )
157
250
{
158
- return new MSBuildArgs ( additionalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
251
+ return new MSBuildArgs (
252
+ additionalProperties ,
253
+ RestoreGlobalProperties ,
254
+ RequestedTargets ,
255
+ GetProperty ,
256
+ GetItem ,
257
+ GetTargetResult ,
258
+ GetResultOutputFile ,
259
+ Verbosity ,
260
+ OtherMSBuildArgs . ToArray ( ) ) ;
159
261
}
160
262
161
263
var newProperties = new Dictionary < string , string > ( GlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
162
264
foreach ( var kvp in additionalProperties )
163
265
{
164
266
newProperties [ kvp . Key ] = kvp . Value ;
165
267
}
166
- return new MSBuildArgs ( new ( newProperties ) , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
268
+ return new MSBuildArgs (
269
+ new ( newProperties ) ,
270
+ RestoreGlobalProperties ,
271
+ RequestedTargets ,
272
+ GetProperty ,
273
+ GetItem ,
274
+ GetTargetResult ,
275
+ GetResultOutputFile ,
276
+ Verbosity ,
277
+ OtherMSBuildArgs . ToArray ( ) ) ;
167
278
}
168
279
169
280
public MSBuildArgs CloneWithAdditionalTargets ( params ReadOnlySpan < string > additionalTargets )
170
281
{
171
282
string [ ] newTargets = RequestedTargets is not null
172
283
? [ .. RequestedTargets , .. additionalTargets ]
173
284
: [ .. additionalTargets ] ;
174
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , newTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
285
+ return new MSBuildArgs (
286
+ GlobalProperties ,
287
+ RestoreGlobalProperties ,
288
+ newTargets ,
289
+ GetProperty ,
290
+ GetItem ,
291
+ GetTargetResult ,
292
+ GetResultOutputFile ,
293
+ Verbosity ,
294
+ OtherMSBuildArgs . ToArray ( ) ) ;
175
295
}
176
296
177
297
public MSBuildArgs CloneWithVerbosity ( VerbosityOptions newVerbosity )
178
298
{
179
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , newVerbosity , OtherMSBuildArgs . ToArray ( ) ) ;
299
+ return new MSBuildArgs (
300
+ GlobalProperties ,
301
+ RestoreGlobalProperties ,
302
+ RequestedTargets ,
303
+ GetProperty ,
304
+ GetItem ,
305
+ GetTargetResult ,
306
+ GetResultOutputFile ,
307
+ newVerbosity ,
308
+ OtherMSBuildArgs . ToArray ( ) ) ;
180
309
}
181
310
182
311
/// <summary>
0 commit comments