@@ -12,11 +12,12 @@ 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 , string [ ] ? otherMSBuildArgs )
15
+ private MSBuildArgs ( ReadOnlyDictionary < string , string > ? properties , ReadOnlyDictionary < string , string > ? restoreProperties , string [ ] ? targets , VerbosityOptions ? verbosity , string [ ] ? otherMSBuildArgs )
16
16
{
17
17
GlobalProperties = properties ;
18
18
RestoreGlobalProperties = restoreProperties ;
19
19
RequestedTargets = targets ;
20
+ Verbosity = verbosity ;
20
21
OtherMSBuildArgs = otherMSBuildArgs is not null
21
22
? [ .. otherMSBuildArgs ]
22
23
: new List < string > ( ) ;
@@ -36,9 +37,11 @@ private MSBuildArgs(ReadOnlyDictionary<string, string>? properties, ReadOnlyDict
36
37
/// The ordered list of targets that should be passed to MSBuild.
37
38
/// </summary>
38
39
public string [ ] ? RequestedTargets { get ; }
40
+ public VerbosityOptions ? Verbosity { get ; }
39
41
40
42
/// <summary>
41
- /// All non <c>-p</c> and <c>-rp</c> arguments that should be passed to MSBuild.
43
+ /// All other arguments that aren't already explicitly modeled by this structure.
44
+ /// The main categories of these today are logger configurations
42
45
/// </summary>
43
46
public List < string > OtherMSBuildArgs { get ; }
44
47
@@ -64,26 +67,34 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
64
67
var globalProperties = parseResult . GetResult ( "--property" ) is OptionResult propResult ? propResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
65
68
var restoreProperties = parseResult . GetResult ( "--restoreProperty" ) is OptionResult restoreResult ? restoreResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
66
69
var requestedTargets = parseResult . GetResult ( "--target" ) is OptionResult targetResult ? targetResult . GetValueOrDefault < string [ ] ? > ( ) : null ;
70
+ var verbosity = parseResult . GetResult ( "--verbosity" ) is OptionResult verbosityResult
71
+ ? verbosityResult . GetValueOrDefault < VerbosityOptions ? > ( )
72
+ : null ;
67
73
var otherMSBuildArgs = parseResult . UnmatchedTokens . ToArray ( ) ;
68
74
return new MSBuildArgs (
69
75
properties : globalProperties ,
70
76
restoreProperties : restoreProperties ,
71
77
targets : requestedTargets ,
72
- otherMSBuildArgs : otherMSBuildArgs ) ;
78
+ otherMSBuildArgs : otherMSBuildArgs ,
79
+ verbosity : verbosity ) ;
73
80
}
74
81
75
82
76
83
public static MSBuildArgs FromProperties ( ReadOnlyDictionary < string , string > ? properties )
77
84
{
78
- return new MSBuildArgs ( properties , null , null , null ) ;
85
+ return new MSBuildArgs ( properties , null , null , null , null ) ;
79
86
}
80
87
81
88
public static MSBuildArgs FromOtherArgs ( params ReadOnlySpan < string > args )
82
89
{
83
- return new MSBuildArgs ( null , null , null , args . ToArray ( ) ) ;
90
+ return new MSBuildArgs ( null , null , null , null , args . ToArray ( ) ) ;
91
+ }
92
+ public static MSBuildArgs FromVerbosity ( VerbosityOptions verbosity )
93
+ {
94
+ return new MSBuildArgs ( null , null , null , verbosity , null ) ;
84
95
}
85
96
86
- public static readonly MSBuildArgs ForHelp = new ( null , null , null , [ "--help" ] ) ;
97
+ public static readonly MSBuildArgs ForHelp = new ( null , null , null , null , [ "--help" ] ) ;
87
98
88
99
/// <summary>
89
100
/// Completely replaces the MSBuild arguments with the provided <paramref name="newArgs"/>.
@@ -94,7 +105,8 @@ public MSBuildArgs CloneWithExplicitArgs(string[] newArgs)
94
105
properties : GlobalProperties ,
95
106
restoreProperties : RestoreGlobalProperties ,
96
107
targets : RequestedTargets ,
97
- otherMSBuildArgs : newArgs ) ;
108
+ otherMSBuildArgs : newArgs ,
109
+ verbosity : Verbosity ) ;
98
110
}
99
111
100
112
/// <summary>
@@ -105,60 +117,71 @@ public MSBuildArgs CloneWithAdditionalArgs(params string[] additionalArgs)
105
117
if ( additionalArgs is null || additionalArgs . Length == 0 )
106
118
{
107
119
// If there are no additional args, we can just return the current instance.
108
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
120
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
109
121
}
110
122
111
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
123
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
112
124
}
113
125
114
126
public MSBuildArgs CloneWithAdditionalRestoreProperties ( ReadOnlyDictionary < string , string > ? additionalRestoreProperties )
115
127
{
116
128
if ( additionalRestoreProperties is null || additionalRestoreProperties . Count == 0 )
117
129
{
118
130
// If there are no additional restore properties, we can just return the current instance.
119
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
131
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
120
132
}
121
133
if ( RestoreGlobalProperties is null )
122
134
{
123
- return new MSBuildArgs ( GlobalProperties , additionalRestoreProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
135
+ return new MSBuildArgs ( GlobalProperties , additionalRestoreProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
124
136
}
125
137
126
138
var newRestoreProperties = new Dictionary < string , string > ( RestoreGlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
127
139
foreach ( var kvp in additionalRestoreProperties )
128
140
{
129
141
newRestoreProperties [ kvp . Key ] = kvp . Value ;
130
142
}
131
- return new MSBuildArgs ( GlobalProperties , new ( newRestoreProperties ) , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
143
+ return new MSBuildArgs ( GlobalProperties , new ( newRestoreProperties ) , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
132
144
}
133
145
134
146
public MSBuildArgs CloneWithAdditionalProperties ( ReadOnlyDictionary < string , string > ? additionalProperties )
135
147
{
136
148
if ( additionalProperties is null || additionalProperties . Count == 0 )
137
149
{
138
150
// If there are no additional properties, we can just return the current instance.
139
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
151
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
140
152
}
141
153
if ( GlobalProperties is null )
142
154
{
143
- return new MSBuildArgs ( additionalProperties , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
155
+ return new MSBuildArgs ( additionalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
144
156
}
145
157
146
158
var newProperties = new Dictionary < string , string > ( GlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
147
159
foreach ( var kvp in additionalProperties )
148
160
{
149
161
newProperties [ kvp . Key ] = kvp . Value ;
150
162
}
151
- return new MSBuildArgs ( new ( newProperties ) , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
163
+ return new MSBuildArgs ( new ( newProperties ) , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
152
164
}
153
165
154
166
public MSBuildArgs CloneWithAdditionalTarget ( string additionalTarget )
155
167
{
156
168
string [ ] newTargets = RequestedTargets is not null
157
169
? [ .. RequestedTargets , additionalTarget ]
158
170
: [ additionalTarget ] ;
159
- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , newTargets , OtherMSBuildArgs . ToArray ( ) ) ;
171
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , newTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
160
172
}
161
173
174
+ public MSBuildArgs CloneWithVerbosity ( VerbosityOptions newVerbosity )
175
+ {
176
+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , newVerbosity , OtherMSBuildArgs . ToArray ( ) ) ;
177
+ }
178
+
179
+ /// <summary>
180
+ /// This mutates the <see cref="MSBuildArgs"/> instance, applying all of the current global properties
181
+ /// to the restore properties dictionary. This is necessary because MSBuild's processing of restore properties
182
+ /// is _exclusive_ - as soon as it sees a <c>-rp</c> flag, it will not apply any <c>-p</c> flags
183
+ /// to the implicit restore operation.
184
+ /// </summary>
162
185
public void ApplyPropertiesToRestore ( )
163
186
{
164
187
if ( RestoreGlobalProperties is null )
0 commit comments