FAKE - F# Make - A DSL for build tasks and more FAKE
6.1.3
Edit this page

Lookig for older versions of the documentation, pre FAKE v6? See 

v5.fake.build

Run the 'dotnet' sdk command line tool

The dotnet command line tool can build and publish projects.

Minimal working example

#r "paket:
nuget Fake.DotNet.Cli //"
open Fake.DotNet

// Lazily install DotNet SDK in the correct version if not available
let install = lazy DotNet.install DotNet.Versions.Release_2_1_4

// Alternative: Read from global json
let install = lazy DotNet.install DotNet.Versions.FromGlobalJson

// Define general properties across various commands (with arguments)
let inline withWorkDir wd =
    DotNet.Options.lift install.Value
    >> DotNet.Options.withWorkingDirectory wd

// Set general properties without arguments
let inline dotnetSimple arg = DotNet.Options.lift install.Value arg

// Use defined properties on "DotNet.Exec"
DotNet.exec (withWorkDir "./test") "build" ""
DotNet.exec dotnetSimple "build" "myproject.fsproj"
DotNet.exec dotnetSimple "build" "mysolution.sln"

// Use defined properties on more generalized functions like "DotNet.Restore"
DotNet.restore dotnetSimple "mysolution.sln"

// Define more general properties in addition to the general ones
DotNet.restore (fun args ->
    { args with
        NoCache = true
    } |> dotnetSimple) "mysolution.sln"

// Define more general properties in addition to the general ones, with arugments
DotNet.restore (fun args ->
    { args with
        Runtime = Some "win-x86"
    } |> withWorkDir "./test" ) "mysolution.sln"

More on API Documentation

SDK tools (local, global, cli-reference)

Some dotnet SDK based tools support project or path based installation. These tools have a ToolType parameter in addition to the ToolPath or ExePath parameters.

Note: If your tool doesn't have this parameter please send a pull request to add it. See the ReportGenerator.fs file changes in PR 2399 on an example what needs to be changed. Basically CreateProcess.withFramework is replaced with CreateProcess.withToolType.

You can use the parameter similar to this (in this example to start the report-generator as local tool with dotnet reportgenerator):

let install = lazy DotNet.install DotNet.Versions.FromGlobalJson
Target.create "Generate Reports" (fun _ ->
  let parameters p = { p with ToolType = ToolType.CreateLocalTool(install.Value) }
  !! "**/opencover.xml"
  |> ReportGenerator.generateReports parameters
)

Here are the possible options:

To set a different tool command (first argument of dotnet) DotNet.Option, for example because you use your own package with a different tool name. You can use:

    { p with
        ToolType =
            ToolType.CreateLocalTool(install.Value)
            |> ToolType.withDefaultToolCommandName "alternative"  }

This will call dotnet alternative <arguments>