@@ -109,19 +109,15 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
109109 }
110110
111111 var parseResult = fakeCommand . Parse ( [ .. forwardedAndUserFacingArgs ] , _analysisParsingConfiguration ) ;
112- var globalProperties = parseResult . GetResult ( "--property" ) is OptionResult propResult ? propResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
113- var restoreProperties = parseResult . GetResult ( "--restoreProperty" ) is OptionResult restoreResult ? restoreResult . GetValueOrDefault < ReadOnlyDictionary < string , string > ? > ( ) : null ;
114- var requestedTargets = parseResult . GetResult ( "--target" ) is OptionResult targetResult ? targetResult . GetValueOrDefault < string [ ] ? > ( ) : null ;
112+ var globalProperties = TryGetValue < ReadOnlyDictionary < string , string > ? > ( "--property" ) ;
113+ var restoreProperties = TryGetValue < ReadOnlyDictionary < string , string > ? > ( "--restoreProperty" ) ;
114+ var requestedTargets = TryGetValue < string [ ] ? > ( "--target" ) ;
115115 var getProperty = TryGetValue < string [ ] > ( "--getProperty" ) ;
116116 var getItem = TryGetValue < string [ ] ? > ( "--getItem" ) ;
117117 var getTargetResult = TryGetValue < string [ ] ? > ( "--getTargetResult" ) ;
118118 var getResultOutputFile = TryGetValue < string [ ] ? > ( "--getResultOutputFile" ) ;
119- var verbosity = parseResult . GetResult ( "--verbosity" ) is OptionResult verbosityResult
120- ? verbosityResult . GetValueOrDefault < VerbosityOptions ? > ( )
121- : null ;
122- var nologo = parseResult . GetResult ( "--nologo" ) is OptionResult nologoResult
123- ? nologoResult . GetValueOrDefault < bool > ( )
124- : false ;
119+ var verbosity = TryGetValue < VerbosityOptions ? > ( "--verbosity" ) ;
120+ var nologo = TryGetValue < bool > ( "--nologo" ) || true ; // Default to nologo if not specified
125121 var otherMSBuildArgs = parseResult . UnmatchedTokens . ToArray ( ) ;
126122 return new MSBuildArgs (
127123 properties : globalProperties ,
@@ -135,6 +131,9 @@ public static MSBuildArgs AnalyzeMSBuildArguments(IEnumerable<string> forwardedA
135131 verbosity : verbosity ,
136132 noLogo : nologo ) ;
137133
134+ /// We can't use <see cref="ParseResult.GetResult(string)"/> to check if the names of the options we care
135+ /// about were specified, because if they weren't specified it throws.
136+ /// So we first check if the option was specified, and only then get its value.
138137 T ? TryGetValue < T > ( string name )
139138 {
140139 return options . Any ( o => o . Name == name ) ? parseResult . GetValue < T > ( name ) : default ;
0 commit comments