Skip to content

Commit 1e313f6

Browse files
committed
Add documentation section on running analyzers after build with configuration options
1 parent 380cf3f commit 1e313f6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/content/getting-started/MSBuild.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,30 @@ We often add a dummy target to a project to print out some values:
195195

196196
Run `dotnet msbuild YourProject.fsproj /t:Dump` and verify that `CodeRoot` has a value or not.
197197

198+
## Analyze FSharp Projects After Build
199+
200+
If you'd like the analyzer to be ran after a build, you can set `RunAnalyzersDuringBuild` or `RunAnalyzers` to `true` in your project file:
201+
202+
```xml
203+
<PropertyGroup>
204+
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
205+
<FSharpAnalyzersOtherFlags>similar to previous section</FSharpAnalyzersOtherFlags>
206+
</PropertyGroup>
207+
```
208+
209+
This is reusing the [Roslyn Analyzers variables](https://learn.microsoft.com/en-us/visualstudio/code-quality/disable-code-analysis?view=vs-2022#net-framework-projects-1). For brevity, here are the relevant variables:
210+
211+
- `RunAnalyzersDuringBuild` : Controls whether analyzers run at build time.
212+
- `RunAnalyzers` : It takes precedence over `RunAnalyzersDuringBuild` and is used to control whether analyzers run at build time or not.
213+
214+
This will run after the `CoreCompile` [target](https://github.com/dotnet/fsharp/blob/dd929579fc275ab99fd496da34bbe6bdade73c86/src/FSharp.Build/Microsoft.FSharp.Targets#L279-L280), which is the default target for building F# projects. The benefit of running after the `CoreCompile` target is this will speed up the analyzers execution as it will attempt to re-use the F# Compiler command line args `FscCommandLineArgs` property to run the analyzers without requiring a [design-time build](https://github.com/dotnet/project-system/blob/main/docs/design-time-builds.md).
215+
216+
However, this target might be skipped if the project is not built again due to [incremental builds](https://learn.microsoft.com/en-us/visualstudio/msbuild/incremental-builds?view=vs-2022). If you want to run the analyzers after every build, you can set `FSharpAnalyzers_AlwaysRunAfterBuild` to `true`:
217+
218+
```xml
219+
<PropertyGroup>
220+
<FSharpAnalyzers_AlwaysRunAfterBuild>true</FSharpAnalyzers_AlwaysRunAfterBuild>
221+
</PropertyGroup>
222+
```
223+
198224
[Next]({{fsdocs-next-page-link}})

0 commit comments

Comments
 (0)