Skip to content

Instantly share code, notes, and snippets.

@kMutagene
Last active September 2, 2020 14:35
Show Gist options
  • Save kMutagene/7cc3b149787b56985be12718a7d0698f to your computer and use it in GitHub Desktop.
Save kMutagene/7cc3b149787b56985be12718a7d0698f to your computer and use it in GitHub Desktop.
Create minimal F# project
#r "paket:
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem
nuget Fake.Core.Target
nuget Fake.Core.ReleaseNotes
nuget Fake.Dotnet.Paket //"
#load ".fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
Target.initEnvironment ()
let release = ReleaseNotes.load "RELEASE_NOTES.md"
Target.create "Clean" (fun _ ->
!! "src/**/bin"
++ "src/**/obj"
|> Shell.cleanDirs
)
Target.create "Build" (fun _ ->
!! "src/**/*.*proj"
|> Seq.iter (DotNet.build id)
)
//Use Dotnet.pack if you dont use paket
Target.create "Pack" (fun _ ->
Paket.pack(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
OutputPath = "nuget"
Version = release.NugetVersion
ReleaseNotes = release.Notes |> String.toLines })
)
Target.create "All" ignore
"Clean"
==> "Build"
==> "Pack"
==> "All"
Target.runOrDefaultWithArguments "All"

0.a Ensure newest dotnet SDK version

0.b Init repo with appropriate license and gitignore (e.g. Visual Studio)

0.c Clone repo

  1. Install Fake template : dotnet new -i "fake-template::*"

  2. In the repo root:

    • dotnet new fake (creates basic build script)
    • dotnet new global.json (locks minimum dotnet SDK version)
    • mkdir src
  3. in the src directory:

    • dotnet new classlib --framework netstandard2.1 -lang F# -n "myProj" (adapt arguments accordingly)
  4. Back in the project root:

    • dotnet new sln(creates .sln file with the same name as the root directory)
    • dotnet sln .\testproj.sln add .\src\myProj\myProj.fsproj --in-root (adapt names of sln and fsproj files accordingly)
    • create a RELEASE_NOTES.md in the project root (for versioning of the nuget package) like this
  5. (If you want to use paket) In the project root:

    • dotnet tool install paket
    • dotnet paket init
    • dotnet paket add {YourPackage} (reference the packages you need)
  6. Create a paket.references file containing the referencces needed for the project in src/myProj

  7. in src/myProj, use dotnet paket install

  8. For nuget package generation:

    • replace contents of build.fsx with the script above (this may lead to future incompatibilities, bit this gist is only thought of as a temporary helper).
    • in src/myProj create a paket.template file like this
  9. you can now build the project and package using ./fake.cmd build from the project root.

  10. Further things that will make this not so much 'minimal' anymore:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment