You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, the path to the analyzer DLL files could be tricky to get right across a wide range of setups.
42
42
Luckily, we can use an MSBuild custom target to take care of the path construction.
43
43
44
+
Note: If using MSBuild is not the right solution for you, you can also [call the analyzers from a FAKE build script](#Call-Analyzers-in-Your-FAKE-Build).
45
+
44
46
Add [FSharp.Analyzers.Build](https://www.nuget.org/packages/FSharp.Analyzers.Build) to your `fsproj`:
45
47
46
48
```xml
@@ -186,4 +188,63 @@ We often add a dummy target to a project to print out some values:
186
188
187
189
Run `dotnet msbuild YourProject.fsproj /t:Dump` and verify that `CodeRoot` has a value or not.
188
190
189
-
[Next]({{fsdocs-next-page-link}})
191
+
## Call Analyzers in Your FAKE Build
192
+
193
+
The below example assumes:
194
+
195
+
1. You have the `fsharp-analyzers` dotnet tool installed
196
+
2. You are using [FAKE](https://fake.build/) as your build automation
197
+
3. You are using [Paket](https://github.com/fsprojects/Paket) as your package manager
198
+
199
+
You can adapt this example to work with other build automation tools and package managers.
200
+
201
+
```fsharp
202
+
open Fake.Api
203
+
open Fake.Core
204
+
open Fake.DotNet
205
+
open Fake.IO
206
+
open Fake.IO.Globbing.Operators
207
+
open System.IO
208
+
209
+
let restore _ =
210
+
// this is a dummy example of how you can restore your solution
211
+
let setParams : DotNet.RestoreOptions -> DotNet.RestoreOptions = id
212
+
DotNet.restore setParams "MySolution.sln"
213
+
214
+
let runAnalyzers args = DotNet.exec id "fsharp-analyzers" args
215
+
216
+
let analyze _ =
217
+
// this example is using paket as our package manager & we have our analyzers in a group called "analyzers"
218
+
// however you can grab your analyzers from anywhere
219
+
let analyzerPaths = !! "packages/analyzers/**/analyzers/dotnet/fs"
220
+
221
+
let createArgsForProject (project: string) analyzerPaths =
222
+
[
223
+
"--project"
224
+
project
225
+
"--analyzers-path"
226
+
yield! analyzerPaths
227
+
]
228
+
|> String.concat " "
229
+
230
+
// use globbing to get all the fsproj files you want to analyze
231
+
!! "src/**/*.fsproj"
232
+
|> Seq.iter (fun fsproj ->
233
+
let result =
234
+
createArgsForProject fsproj analyzerPaths
235
+
|> runAnalyzers
236
+
237
+
result.Errors
238
+
|> Seq.iter Trace.traceError
239
+
)
240
+
241
+
// other FAKE code here...
242
+
243
+
Target.create "Restore" restore
244
+
Target.create "Analyzers" analyze
245
+
246
+
// example of setting up analyzers in your dependency graph
0 commit comments