Skip to content

Commit cc33cbc

Browse files
committed
Fixing packaging
1 parent 32bfe14 commit cc33cbc

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

build.fsx

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Argu
2+
open System.IO.Compression
23
#load ".fake/build.fsx/intellisense.fsx"
34
#load "docsTool/CLI.fs"
45
#if !FAKE
@@ -528,22 +529,77 @@ let generateAssemblyInfo _ =
528529
| Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes
529530
)
530531

532+
533+
[<AllowNullLiteral>]
534+
type private DisposableDirectory (directory : string) =
535+
static member Create() =
536+
let tempPath = IO.Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString("n"))
537+
Trace.tracefn "Creating disposable directory %s" tempPath
538+
IO.Directory.CreateDirectory tempPath |> ignore
539+
new DisposableDirectory(tempPath)
540+
member x.DirectoryInfo = IO.DirectoryInfo(directory)
541+
interface IDisposable with
542+
member x.Dispose() =
543+
Trace.tracefn "Deleting disposable directory %s" x.DirectoryInfo.FullName
544+
IO.Directory.Delete(x.DirectoryInfo.FullName,true)
545+
531546
let dotnetPack ctx =
532-
// Get release notes with properly-linked version number
533-
let releaseNotes = latestEntry |> Changelog.mkReleaseNotes linkReferenceForLatestEntry
547+
let pack configuration args proj=
548+
DotNet.pack (fun c ->
549+
{ c with
550+
Configuration = configuration
551+
OutputPath = Some distDir
552+
Common =
553+
c.Common
554+
|> DotNet.Options.withAdditionalArgs args
555+
}) proj
556+
557+
let getTargetFramework (proj : string) =
558+
let projDoc = System.Xml.XmlDocument()
559+
projDoc.Load(proj)
560+
projDoc.GetElementsByTagName("TargetFramework").ItemOf(0).InnerText
561+
562+
let configuration = configuration (ctx.Context.AllExecutingTargets)
534563
let args =
535564
[
536565
sprintf "/p:PackageVersion=%s" latestEntry.NuGetVersion
537-
sprintf "/p:PackageReleaseNotes=\"%s\"" releaseNotes
566+
sprintf "/p:PackageReleaseNotes=\"%s\"" (latestEntry |> Changelog.mkReleaseNotes linkReferenceForLatestEntry)
538567
]
539-
DotNet.pack (fun c ->
540-
{ c with
541-
Configuration = configuration (ctx.Context.AllExecutingTargets)
542-
OutputPath = Some distDir
543-
Common =
544-
c.Common
545-
|> DotNet.Options.withAdditionalArgs args
546-
}) sln
568+
!! srcGlob
569+
|> Seq.map(fun proj -> pack configuration args proj ; proj)
570+
|> Seq.filter(fun proj -> proj.Contains "Myriad.Plugins")
571+
|> Seq.iter(fun proj ->
572+
// Myriad Plugins need some additional work to bundle 3rd party dependencies: see https://github.com/ionide/FSharp.Analyzers.SDK#packaging-and-distribution
573+
let publishFramework = getTargetFramework proj
574+
DotNet.publish (fun c ->
575+
{ c with
576+
Configuration = configuration
577+
Framework = Some (publishFramework)
578+
}) proj
579+
580+
let nupkg =
581+
let projectName = IO.Path.GetFileNameWithoutExtension proj
582+
IO.Directory.GetFiles distDir
583+
|> Seq.filter(fun path -> path.Contains projectName)
584+
|> Seq.tryExactlyOne
585+
|> Option.defaultWith(fun () -> failwithf "Could not find corresponsiding nuget package with name containing %s" projectName )
586+
|> IO.FileInfo
587+
588+
let publishPath = IO.FileInfo(proj).Directory.FullName </> "bin" </> (string configuration) </> publishFramework </> "publish"
589+
590+
use dd = DisposableDirectory.Create()
591+
// Unzip the nuget
592+
ZipFile.ExtractToDirectory(nupkg.FullName, dd.DirectoryInfo.FullName)
593+
// delete the initial nuget package
594+
nupkg.Delete()
595+
// remove stuff from ./lib/{{publishFramework}}
596+
Shell.deleteDir (dd.DirectoryInfo.FullName </> "lib" </> publishFramework)
597+
// move the output of publish folder into the ./lib/{{publishFramework}} directory
598+
Shell.copyDir (dd.DirectoryInfo.FullName </> "lib" </> publishFramework) publishPath (fun _ -> true)
599+
// re-create the nuget package
600+
ZipFile.CreateFromDirectory(dd.DirectoryInfo.FullName, nupkg.FullName)
601+
)
602+
547603

548604
let sourceLinkTest _ =
549605
!! distGlob

0 commit comments

Comments
 (0)