@@ -58,6 +58,7 @@ type Arguments =
5858 | [<Unique>] Code_ Root of string
5959 | [<Unique; AltCommandLine( " -v" ) >] Verbosity of string
6060 | [<Unique>] Output_ Format of string
61+ | [<Unique>] BinLog_ Path of string
6162
6263 interface IArgParserTemplate with
6364 member s.Usage =
@@ -92,7 +93,8 @@ type Arguments =
9293 | Code_ Root _ ->
9394 " Root of the current code repository, used in the sarif report to construct the relative file path. The current working directory is used by default."
9495 | Output_ Format _ ->
95- " Format in which to write analyzer results to stdout. The available options are: default, github."
96+ " Format in which to write analyzer results to stdout. The available options are: default, github."
97+ | BinLog_ Path(_) -> " Path to a directory where MSBuild binary logs (binlog) will be written. You can use https://msbuildlog.com/ to view them."
9698
9799type SeverityMappings =
98100 {
@@ -157,7 +159,7 @@ let mutable logger: ILogger = Abstractions.NullLogger.Instance
157159
158160/// <summary>Runs MSBuild to create FSharpProjectOptions based on the projPaths.</summary>
159161/// <returns>Returns only the FSharpProjectOptions based on the projPaths and not any referenced projects.</returns>
160- let loadProjects toolsPath properties ( projPaths : string list ) =
162+ let loadProjects toolsPath properties ( projPaths : string list ) ( binLogPath : DirectoryInfo option ) =
161163 async {
162164 let projPaths =
163165 projPaths
@@ -167,7 +169,16 @@ let loadProjects toolsPath properties (projPaths: string list) =
167169 logger.LogInformation( " Loading project {0}" , proj)
168170
169171 let loader = WorkspaceLoader.Create( toolsPath, properties)
170- let projectOptions = loader.LoadProjects projPaths
172+ binLogPath
173+ |> Option.iter ( fun path ->
174+ logger.LogInformation( " Using binary log path: {0}" , path.FullName)
175+ )
176+ let binLogConfig =
177+ binLogPath
178+ |> Option.map ( fun path -> BinaryLogGeneration.Within path)
179+ |> Option.defaultValue BinaryLogGeneration.Off
180+
181+ let projectOptions = loader.LoadProjects( projPaths, [], binaryLog = binLogConfig)
171182
172183 let failedLoads =
173184 projPaths
@@ -593,10 +604,18 @@ let main argv =
593604 |> ignore
594605 )
595606
596- logger <- factory.CreateLogger( " " )
607+ logger <- factory.CreateLogger( " FSharp.Analyzers.Cli" )
608+
609+ // Set the Ionide.ProjInfo logger to use the same Microsoft.Extensions.Logging logger
610+ if logLevel <= LogLevel.Information then
611+ Ionide.ProjInfo.Logging.Providers.MicrosoftExtensionsLoggingProvider.setMicrosoftLoggerFactory factory
597612
598613 logger.LogInformation( " Running in verbose mode" )
599614
615+ let binlogPath =
616+ results.TryGetResult <@ BinLog_ Path @>
617+ |> Option.map ( Path.GetFullPath >> DirectoryInfo)
618+
600619 AppDomain.CurrentDomain.UnhandledException.Add( fun args ->
601620 let ex = args.ExceptionObject :?> exn
602621
@@ -808,7 +827,7 @@ let main argv =
808827 exit ( int ExitErrorCodes.InvalidProjectArguments)
809828 async {
810829 let! scriptOptions = scriptOptions |> Async.StartChild
811- let! loadedProjects = loadProjects toolsPath properties projects |> Async.StartChild
830+ let! loadedProjects = loadProjects toolsPath properties projects binlogPath |> Async.StartChild
812831 let! loadedProjects = loadedProjects
813832 let! scriptOptions = scriptOptions
814833
0 commit comments