11<Project >
2+
3+ <PropertyGroup >
4+ <_AnalyzerProjectOptions >--project " $(MSBuildProjectFile)" </_AnalyzerProjectOptions >
5+ </PropertyGroup >
6+
27 <Target Name =" _AnalyzeFSharpProject" >
38 <Error Condition =" $(FSharpAnalyzersOtherFlags) == ''" Text =" A property FSharpAnalyzersOtherFlags should exists with all the analyzer cli arguments!" />
49 <Exec
510 ContinueOnError =" true"
611 IgnoreExitCode =" true"
7- Command =" dotnet fsharp-analyzers --project " $(MSBuildProjectFile) " $(FSharpAnalyzersOtherFlags)" />
12+ Command =" dotnet fsharp-analyzers $(_AnalyzerProjectOptions) $(FSharpAnalyzersOtherFlags)" />
813 </Target >
914
1015 <Target Name =" AnalyzeFSharpProject" DependsOnTargets =" _AnalyzeFSharpProject" />
16+
17+ <Target Name =" _SetupFSharpAnalyzerProjectOptions" BeforeTargets =" CoreCompile" Condition =" '$(RunAnalyzers)' == 'true'" >
18+ <PropertyGroup >
19+ <!--
20+ Required for F# Targets CoreCompile to output command line arguments
21+ https://github.com/dotnet/fsharp/blob/53929f2e01281a614a15033dfaae6fb6d00bb543/src/FSharp.Build/Fsc.fs#L721-L725
22+ https://github.com/dotnet/fsharp/blob/53929f2e01281a614a15033dfaae6fb6d00bb543/src/FSharp.Build/Microsoft.FSharp.Targets#L418C19-L418C32
23+ -->
24+ <ProvideCommandLineArgs >true</ProvideCommandLineArgs >
25+ </PropertyGroup >
26+ </Target >
27+
28+ <Target Name =" FsharpAnalyzerAfterBuild" DependsOnTargets =" _SetupFSharpAnalyzerProjectOptions" AfterTargets =" AfterBuild" Condition =" '$(RunAnalyzers)' == 'true'" >
29+ <Error Condition =" $(FSharpAnalyzersOtherFlags) == ''" Text =" A property FSharpAnalyzersOtherFlags should exists with all the analyzer cli arguments!" />
30+ <!--
31+ Question: Should we only execute this target if FscCommandLineArgs is not empty?
32+ Argument for Incremental builds may skip CoreCompile if no files changed, so we don't want to run the analyzer in that case.
33+ There may be a better way to detect if CoreCompile was skipped but this seems to work.
34+ And if someone wants to run the analyzer without FscCommandLineArgs, they can run the AnalyzeFSharpProject target directly.
35+ -->
36+ <PropertyGroup >
37+ <_AnalyzerProjectOptions Condition =" '@(FscCommandLineArgs->Count())' != '0'" >--fsc-args " @(FscCommandLineArgs)" </_AnalyzerProjectOptions >
38+ </PropertyGroup >
39+ <Exec
40+ ContinueOnError =" true"
41+ IgnoreExitCode =" true"
42+ Condition =" '@(FscCommandLineArgs->Count())' != '0'"
43+ Command =" dotnet fsharp-analyzers $(_AnalyzerProjectOptions) $(FSharpAnalyzersOtherFlags)" />
44+
45+ </Target >
1146</Project >
0 commit comments