-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathnupkg-hack.fsx
45 lines (39 loc) · 2.07 KB
/
nupkg-hack.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#r "System.IO.Compression"
open System
open System.IO
open System.IO.Compression
open System.Text
open System.Text.RegularExpressions
open Fake.Core
open Fake.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let changeVersionConstraints text =
Regex("(?<=id=\"Interstellar.+?\"\\s+version=\")[^[\\]]*?(?=\")")
.Replace (text, MatchEvaluator(fun m -> sprintf "[%s]" m.Value))
// """<group targetFramework=".NETFramework4.7.2">
// <dependency id="Interstellar.Chromium" version="0.2.0-rc" exclude="Build,Analyzers" />
// <dependency id="Interstellar.Core" version="0.2.0-rc" exclude="Build,Analyzers" />
// <dependency id="CefSharp.Wpf" version="75.1.143" exclude="Build,Analyzers" />
// <dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
// </group>
// <group targetFramework=".NETCoreApp3.0">
// <dependency id="Interstellar.Chromium" version="0.2.0-rc" exclude="Build,Analyzers" />
// <dependency id="Interstellar.Core" version="0.2.0-rc" exclude="Build,Analyzers" />
// <dependency id="CefSharp.Wpf" version="75.1.143" exclude="Build,Analyzers" />
// <dependency id="FSharp.Core" version="4.2.3" exclude="Build,Analyzers" />
// </group>"""
// |> changeVersionConstraints |> printfn "%s"
let hackNupkgFromStream (_: string) (stream: Stream) =
use archive = new ZipArchive(stream, ZipArchiveMode.Update)
let oldEntry = archive.Entries |> Seq.find (fun e -> e.Name.EndsWith ".nuspec")
let input =
(use nuspecReader = new StreamReader(oldEntry.Open(), Encoding.UTF8) in nuspecReader.ReadToEnd())
let output = changeVersionConstraints input
use nuspecWriter = new StreamWriter(oldEntry.Open(), Encoding.UTF8)
nuspecWriter.Write output
/// Cracks open a nupkg and changes all Interstellar package reference constraints from >= to =
let hackNupkgAtPath (path: string) =
Trace.log ("Hacking nupkg: " + path)
use file = File.Open (path, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
hackNupkgFromStream path file
//hackNupkgAtPath (Path.Combine ("artifacts", "Interstellar.Wpf.Chromium.nupkg"))