Skip to content

Commit 9196777

Browse files
committed
Updated getting started docs to include FAKE setup
1 parent ac7d475 commit 9196777

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

docs/content/Getting Started Using.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ dotnet fsharp-analyzers --project ./YourProject.fsproj --analyzers-path C:\Users
4141
As you can see, the path to the analyzer DLL files could be tricky to get right across a wide range of setups.
4242
Luckily, we can use an MSBuild custom target to take care of the path construction.
4343

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+
4446
Add [FSharp.Analyzers.Build](https://www.nuget.org/packages/FSharp.Analyzers.Build) to your `fsproj`:
4547

4648
```xml
@@ -186,4 +188,63 @@ We often add a dummy target to a project to print out some values:
186188

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

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
247+
"Restore" ==> "Analyzers" |> ignore
248+
```
249+
250+
[Next]({{fsdocs-next-page-link}})

0 commit comments

Comments
 (0)