@@ -12,11 +12,12 @@ namespace Microsoft.DotNet.Cli.Utils;
1212/// </summary>
1313public sealed class MSBuildArgs
1414{
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 )
1616 {
1717 GlobalProperties = properties ;
1818 RestoreGlobalProperties = restoreProperties ;
1919 RequestedTargets = targets ;
20+ Verbosity = verbosity ;
2021 OtherMSBuildArgs = otherMSBuildArgs is not null
2122 ? [ .. otherMSBuildArgs ]
2223 : new List < string > ( ) ;
@@ -36,9 +37,11 @@ private MSBuildArgs(ReadOnlyDictionary<string, string>? properties, ReadOnlyDict
3637 /// The ordered list of targets that should be passed to MSBuild.
3738 /// </summary>
3839 public string [ ] ? RequestedTargets { get ; }
40+ public VerbosityOptions ? Verbosity { get ; }
3941
4042 /// <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
4245 /// </summary>
4346 public List < string > OtherMSBuildArgs { get ; }
4447
@@ -64,26 +67,34 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
6467 var globalProperties = parseResult . GetResult ( "--property" ) is OptionResult propResult ? propResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
6568 var restoreProperties = parseResult . GetResult ( "--restoreProperty" ) is OptionResult restoreResult ? restoreResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
6669 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 ;
6773 var otherMSBuildArgs = parseResult . UnmatchedTokens . ToArray ( ) ;
6874 return new MSBuildArgs (
6975 properties : globalProperties ,
7076 restoreProperties : restoreProperties ,
7177 targets : requestedTargets ,
72- otherMSBuildArgs : otherMSBuildArgs ) ;
78+ otherMSBuildArgs : otherMSBuildArgs ,
79+ verbosity : verbosity ) ;
7380 }
7481
7582
7683 public static MSBuildArgs FromProperties ( ReadOnlyDictionary < string , string > ? properties )
7784 {
78- return new MSBuildArgs ( properties , null , null , null ) ;
85+ return new MSBuildArgs ( properties , null , null , null , null ) ;
7986 }
8087
8188 public static MSBuildArgs FromOtherArgs ( params ReadOnlySpan < string > args )
8289 {
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 ) ;
8495 }
8596
86- public static readonly MSBuildArgs ForHelp = new ( null , null , null , [ "--help" ] ) ;
97+ public static readonly MSBuildArgs ForHelp = new ( null , null , null , null , [ "--help" ] ) ;
8798
8899 /// <summary>
89100 /// Completely replaces the MSBuild arguments with the provided <paramref name="newArgs"/>.
@@ -94,7 +105,8 @@ public MSBuildArgs CloneWithExplicitArgs(string[] newArgs)
94105 properties : GlobalProperties ,
95106 restoreProperties : RestoreGlobalProperties ,
96107 targets : RequestedTargets ,
97- otherMSBuildArgs : newArgs ) ;
108+ otherMSBuildArgs : newArgs ,
109+ verbosity : Verbosity ) ;
98110 }
99111
100112 /// <summary>
@@ -105,60 +117,71 @@ public MSBuildArgs CloneWithAdditionalArgs(params string[] additionalArgs)
105117 if ( additionalArgs is null || additionalArgs . Length == 0 )
106118 {
107119 // 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 ( ) ) ;
109121 }
110122
111- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
123+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , [ .. OtherMSBuildArgs , .. additionalArgs ] ) ;
112124 }
113125
114126 public MSBuildArgs CloneWithAdditionalRestoreProperties ( ReadOnlyDictionary < string , string > ? additionalRestoreProperties )
115127 {
116128 if ( additionalRestoreProperties is null || additionalRestoreProperties . Count == 0 )
117129 {
118130 // 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 ( ) ) ;
120132 }
121133 if ( RestoreGlobalProperties is null )
122134 {
123- return new MSBuildArgs ( GlobalProperties , additionalRestoreProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
135+ return new MSBuildArgs ( GlobalProperties , additionalRestoreProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
124136 }
125137
126138 var newRestoreProperties = new Dictionary < string , string > ( RestoreGlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
127139 foreach ( var kvp in additionalRestoreProperties )
128140 {
129141 newRestoreProperties [ kvp . Key ] = kvp . Value ;
130142 }
131- return new MSBuildArgs ( GlobalProperties , new ( newRestoreProperties ) , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
143+ return new MSBuildArgs ( GlobalProperties , new ( newRestoreProperties ) , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
132144 }
133145
134146 public MSBuildArgs CloneWithAdditionalProperties ( ReadOnlyDictionary < string , string > ? additionalProperties )
135147 {
136148 if ( additionalProperties is null || additionalProperties . Count == 0 )
137149 {
138150 // 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 ( ) ) ;
140152 }
141153 if ( GlobalProperties is null )
142154 {
143- return new MSBuildArgs ( additionalProperties , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
155+ return new MSBuildArgs ( additionalProperties , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
144156 }
145157
146158 var newProperties = new Dictionary < string , string > ( GlobalProperties , StringComparer . OrdinalIgnoreCase ) ;
147159 foreach ( var kvp in additionalProperties )
148160 {
149161 newProperties [ kvp . Key ] = kvp . Value ;
150162 }
151- return new MSBuildArgs ( new ( newProperties ) , RestoreGlobalProperties , RequestedTargets , OtherMSBuildArgs . ToArray ( ) ) ;
163+ return new MSBuildArgs ( new ( newProperties ) , RestoreGlobalProperties , RequestedTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
152164 }
153165
154166 public MSBuildArgs CloneWithAdditionalTarget ( string additionalTarget )
155167 {
156168 string [ ] newTargets = RequestedTargets is not null
157169 ? [ .. RequestedTargets , additionalTarget ]
158170 : [ additionalTarget ] ;
159- return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , newTargets , OtherMSBuildArgs . ToArray ( ) ) ;
171+ return new MSBuildArgs ( GlobalProperties , RestoreGlobalProperties , newTargets , Verbosity , OtherMSBuildArgs . ToArray ( ) ) ;
160172 }
161173
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>
162185 public void ApplyPropertiesToRestore ( )
163186 {
164187 if ( RestoreGlobalProperties is null )
0 commit comments