From 50b21f67c4a1e10a7b9a61560fb165817df48dc2 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Thu, 21 Jul 2016 16:40:19 +0200 Subject: [PATCH] Allow to run arbitrary dotnet CLI commands --- RELEASE_NOTES.md | 3 +- src/app/FakeLib/DotNetCLIHelper.fs | 46 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e86b5b59a6b..58133009128 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,9 +1,10 @@ -#### 4.34.3 - 21.07.2016 +#### 4.34.4 - 21.07.2016 * DotNet version support - https://github.com/fsharp/FAKE/pull/1310 * DotNet test support - https://github.com/fsharp/FAKE/pull/1311 * DotNet build support - https://github.com/fsharp/FAKE/pull/1318 * DotNet pack support - https://github.com/fsharp/FAKE/pull/1313 * Allows to set version in project.json +* Allow to run arbitrary dotnet CLI commands * DotNet restore support - https://github.com/fsharp/FAKE/pull/1309 * BUGFIX: Update DACPAC module - https://github.com/fsharp/FAKE/pull/1307 diff --git a/src/app/FakeLib/DotNetCLIHelper.fs b/src/app/FakeLib/DotNetCLIHelper.fs index c49b6290fa0..f9f4b8b3a78 100644 --- a/src/app/FakeLib/DotNetCLIHelper.fs +++ b/src/app/FakeLib/DotNetCLIHelper.fs @@ -51,6 +51,52 @@ let isInstalled() = processResult.OK +/// DotNet parameters +type CommandParams = { + /// ToolPath - usually just "dotnet" + ToolPath: string + + /// Working directory (optional). + WorkingDir: string + + /// A timeout for the command. + TimeOut: TimeSpan +} + +let private DefaultCommandParams : CommandParams = { + ToolPath = commandName + WorkingDir = Environment.CurrentDirectory + TimeOut = TimeSpan.FromMinutes 30. +} + +/// Runs a dotnet command. +/// ## Parameters +/// +/// - `setCommandParams` - Function used to overwrite the default parameters. +/// - `args` - command and additional arguments. +/// +/// ## Sample +/// +/// !! "src/test/project.json" +/// |> DotNet.Pack +/// (fun p -> +/// { p with +/// Configuration = "Release" }) +let RunCommand (setCommandParams: CommandParams -> CommandParams) args = + traceStartTask "DotNet" "" + + try + let parameters = setCommandParams DefaultCommandParams + + if 0 <> ExecProcess (fun info -> + info.FileName <- parameters.ToolPath + info.WorkingDirectory <- parameters.WorkingDir + info.Arguments <- args) parameters.TimeOut + then + failwithf "Pack failed on %s" args + finally + traceEndTask "DotNet" "" + /// DotNet restore parameters type RestoreParams = { /// ToolPath - usually just "dotnet"