From c5a24c6050be46fd0bb0e5f9cae94b6f391d2f6e Mon Sep 17 00:00:00 2001
From: TeaDrivenDev <TeaDrivenDev@gmail.com>
Date: Sat, 11 Apr 2020 23:17:44 +0200
Subject: [PATCH] Use Paket to create NuGet package

Restrict LiteDB dependency version to 4.x
---
 LiteDB.FSharp/LiteDB.FSharp.fsproj | 13 ++++---------
 LiteDB.FSharp/paket.template       | 17 +++++++++++++++++
 build.fsx                          | 15 +++++++++------
 build.fsx.lock                     |  7 +++++++
 paket.dependencies                 |  2 +-
 5 files changed, 38 insertions(+), 16 deletions(-)
 create mode 100644 LiteDB.FSharp/paket.template

diff --git a/LiteDB.FSharp/LiteDB.FSharp.fsproj b/LiteDB.FSharp/LiteDB.FSharp.fsproj
index 29a5b78..6d7fab4 100644
--- a/LiteDB.FSharp/LiteDB.FSharp.fsproj
+++ b/LiteDB.FSharp/LiteDB.FSharp.fsproj
@@ -1,17 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
-        <Description>Advanced F# Support for LiteDB with query construction through quotation expressions</Description>
-        <PackageProjectUrl>https://github.com/Zaid-Ajaj/LiteDB.FSharp</PackageProjectUrl>
-        <RepositoryUrl>https://github.com/Zaid-Ajaj/LiteDB.FSharp.git</RepositoryUrl>
-        <PackageLicenseUrl>https://github.com/Zaid-Ajaj/LiteDB.FSharp/blob/master/LICENSE</PackageLicenseUrl>
-        <PackageIconUrl></PackageIconUrl>
-        <PackageTags>fsharp;litedb;embedded;database;document-database</PackageTags>
-        <Authors>Zaid Ajaj</Authors>
-        <Version>2.15.0</Version>
         <TargetFrameworks>netstandard2.0;net45;net461</TargetFrameworks>
         <GenerateDocumentationFile>true</GenerateDocumentationFile>
-        <PackageReleaseNotes>Support deserialization of optional lists and arrays (#44)</PackageReleaseNotes>
+        <IsPackable>true</IsPackable>
+    </PropertyGroup>
+    <PropertyGroup>
+      <OutputPath>..\bin</OutputPath>
     </PropertyGroup>
     <ItemGroup>
         <Compile Include="Linq.fs" />
diff --git a/LiteDB.FSharp/paket.template b/LiteDB.FSharp/paket.template
new file mode 100644
index 0000000..fb36b74
--- /dev/null
+++ b/LiteDB.FSharp/paket.template
@@ -0,0 +1,17 @@
+type project
+id LiteDB.FSharp
+version 2.15.1
+authors
+    Zaid Ajaj
+owners
+    Zaid Ajaj
+requirelicenseacceptance false
+licenseurl https://github.com/Zaid-Ajaj/LiteDB.FSharp/blob/master/LICENSE
+projecturl https://github.com/Zaid-Ajaj/LiteDB.FSharp
+description
+    Advanced F# Support for LiteDB with query construction through quotation expressions
+releaseNotes
+    Restrict LiteDB version to 4.x
+include-pdbs false
+tags
+    fsharp litedb embedded database document-database
diff --git a/build.fsx b/build.fsx
index 9debdfe..1cc7a57 100644
--- a/build.fsx
+++ b/build.fsx
@@ -1,6 +1,7 @@
 #r "paket:
 nuget Fake.Core.Target
 nuget Fake.DotNet.Cli
+nuget Fake.DotNet.Paket
 nuget Fake.IO.FileSystem
 //"
 
@@ -25,6 +26,7 @@ Target.create "RunTests" <| fun _ ->
 
 Target.create "Clean" <| fun _ -> 
     [
+        cwd </> "bin"
         projectPath </> "bin"
         projectPath </> "obj"
         testsPath </> "bin"
@@ -42,20 +44,21 @@ Target.create "Build" <| fun _ ->
     DotNet.build setParams (projectPath </> "LiteDB.FSharp.fsproj")
 
 Target.create "PackNuget" <| fun _ ->
-    let setParams (defaults: DotNet.PackOptions) =
+    Paket.pack (fun defaults ->
         {
             defaults with
-                Configuration = DotNet.BuildConfiguration.Release
-        }
-
-    DotNet.pack setParams projectPath
+                TemplateFile = projectPath </> "paket.template"
+                BuildConfig = "Release"
+                MinimumFromLockFile = true
+                OutputPath = cwd </> "bin"
+        })
 
 Target.create "PublishNuget" <| fun _ ->
     let nugetKey =
         match Environment.environVarOrNone "NUGET_KEY" with
         | Some nugetKey -> nugetKey
         | None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"
-    let nupkg = Directory.GetFiles(projectPath </> "bin" </> "Release") |> Seq.head
+    let nupkg = Directory.GetFiles(cwd </> "bin") |> Seq.head
 
     let setParams (defaults: DotNet.NuGetPushOptions) =
         {
diff --git a/build.fsx.lock b/build.fsx.lock
index fcddd95..49926eb 100644
--- a/build.fsx.lock
+++ b/build.fsx.lock
@@ -87,6 +87,13 @@ NUGET
       Newtonsoft.Json (>= 12.0.3)
       NuGet.Protocol (>= 4.9.4)
       System.Net.Http (>= 4.3.4)
+    Fake.DotNet.Paket (5.19.1)
+      Fake.Core.Process (>= 5.19.1)
+      Fake.Core.String (>= 5.19.1)
+      Fake.Core.Trace (>= 5.19.1)
+      Fake.DotNet.Cli (>= 5.19.1)
+      Fake.IO.FileSystem (>= 5.19.1)
+      FSharp.Core (>= 4.7)
     Fake.IO.FileSystem (5.19.1)
       Fake.Core.String (>= 5.19.1)
       FSharp.Core (>= 4.7)
diff --git a/paket.dependencies b/paket.dependencies
index 55cc381..04935a1 100644
--- a/paket.dependencies
+++ b/paket.dependencies
@@ -3,6 +3,6 @@ source https://www.nuget.org/api/v2
 storage:none
 nuget Expecto
 nuget FSharp.Core
-nuget LiteDB
+nuget LiteDB ~> 4.1
 nuget Newtonsoft.JSON
 nuget TypeShape