Skip to content

Instantly share code, notes, and snippets.

@realvictorprm
Last active June 12, 2018 19:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save realvictorprm/d95bf2c45b5cb6cc3afa04465055cb94 to your computer and use it in GitHub Desktop.
Save realvictorprm/d95bf2c45b5cb6cc3afa04465055cb94 to your computer and use it in GitHub Desktop.
A must have for your script file to ease spreading a small proof of concept with dependencies!
open System
open System.IO
open System.Diagnostics
let downloadDependencies deps =
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
async {
let url = "http://fsprojects.github.io/Paket/stable"
use wc = new Net.WebClient()
wc.DownloadProgressChanged.Add(fun a -> printfn "Progress downloading paket.exe: %d" a.ProgressPercentage)
let tmp = Path.GetTempFileName()
let stable = wc.DownloadString(url)
do! wc.AsyncDownloadFile(stable |> Uri, tmp)
File.Move(tmp,Path.GetFileName stable)
} |> Async.RunSynchronously
printfn "Finished downloading paket.exe!"
let invokePaket args =
use process =
new Process(
StartInfo =
new ProcessStartInfo(
FileName = "./paket.exe",
Arguments = args,
UseShellExecute = false))
process.Start() |> ignore
process.WaitForExit()
if not (File.Exists "paket.dependencies") && not (File.Exists "paket.lock") then
invokePaket "init"
for dep in deps do
sprintf "add %s" dep
|> invokePaket
downloadDependencies [ "MathNet.Numerics"; "MathNet.Numerics.FSharp"] // Append the package names to this list!
@amieres
Copy link

amieres commented Jun 6, 2018

Good idea. Although I'm getting this message:

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
ERR :    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
ERR :    at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
ERR :    at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
ERR : --- End of stack trace from previous location where exception was thrown ---
ERR :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
ERR :    at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[a](AsyncImplResult`1 res)
ERR :    at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronouslyInAnotherThread[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout)
ERR :    at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout)
ERR :    at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken)

@NatElkins
Copy link

@amieres What version of Paket are you using? I think I got that once because of some change that Github made, and it required updating my Paket version.

I think I've also "resolved" that error by simply trying it again (was a transient network issue).

@Zagrophyte
Copy link

Zagrophyte commented Jun 6, 2018

@amieres @NatElkins @realvictorprm
Might want to add:
System.Net.ServicePointManager.SecurityProtocol <- System.Net.SecurityProtocolType.Tls12 // Github uses TLS 1.2
to the top of the file after open statements.

@jcmrva
Copy link

jcmrva commented Jun 7, 2018

I get this when pasting downloadDependencies into fsi:

warning FS0046: The identifier 'process' is reserved for future use by F#

@vilinski
Copy link

@amieres that's not about paket. GitHub has disabled TLS <= 1.2 How to enable TLS 1.2.

@amieres
Copy link

amieres commented Jun 12, 2018

@Zagrophyte

Might want to add:
System.Net.ServicePointManager.SecurityProtocol <- System.Net.SecurityProtocolType.Tls12 // Github uses TLS 1.2
to the top of the file after open statements.

You are right! That did the trick.
Thank you!

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