From 35ace1b6c77aa96655e4f39d8e329790aa971b97 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 29 Jan 2024 00:01:51 -0500 Subject: [PATCH] Allow RunSettingsArguments to be set --- src/app/Fake.DotNet.Cli/DotNet.fs | 32 +++++++++++++------ .../Fake.Core.UnitTests/Fake.DotNet.Cli.fs | 20 +++++++++++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/app/Fake.DotNet.Cli/DotNet.fs b/src/app/Fake.DotNet.Cli/DotNet.fs index 4224c5764d7..823b42ea705 100644 --- a/src/app/Fake.DotNet.Cli/DotNet.fs +++ b/src/app/Fake.DotNet.Cli/DotNet.fs @@ -1173,21 +1173,33 @@ module DotNet = MSBuild.addBinaryLogger (common.DotNetCliPath + " msbuild") callMsBuildExe args disableFakeBinLog - let internal execWithBinLog project common command args msBuildArgs = + let internal buildAfterArgs args afterArgs = + [ yield! args + match afterArgs with + | Some a -> + yield "--" + yield a + | None -> () ] + + let internal execWithBinLog project common command args msBuildArgs afterArgs = let msbuildArgList = MSBuild.fromCliArguments msBuildArgs let binLogPath, args = addBinaryLogger msBuildArgs.DisableInternalBinLog (args @ msbuildArgList) common + let args = buildAfterArgs args afterArgs + let result = execArgsList (fun _ -> common) command args MSBuild.handleAfterRun (sprintf "dotnet %s" command) binLogPath result.ExitCode project - let internal tryExecWithBinLog project common command args msBuildArgs = + let internal tryExecWithBinLog project common command args msBuildArgs afterArgs = let msbuildArgList = MSBuild.fromCliArguments msBuildArgs let binLogPath, args = addBinaryLogger msBuildArgs.DisableInternalBinLog (args @ msbuildArgList) common + let args = buildAfterArgs args afterArgs + let result = execArgsList (fun _ -> common) command args try @@ -1230,7 +1242,7 @@ module DotNet = let param = MSBuildOptions.Create() |> setParams let args = [ project ] - execWithBinLog project param.Common "msbuild" args param.MSBuildParams + execWithBinLog project param.Common "msbuild" args param.MSBuildParams None __.MarkSuccess() // TODO: Make this API public? change return code? @@ -1239,7 +1251,9 @@ module DotNet = let param = MSBuildOptions.Create() |> setParams let args = [ project ] - let r = tryExecWithBinLog project param.Common "msbuild" args param.MSBuildParams + + let r = + tryExecWithBinLog project param.Common "msbuild" args param.MSBuildParams None //__.MarkSuccess() r @@ -1326,7 +1340,7 @@ module DotNet = use __ = Trace.traceTask "DotNet:restore" project let param = RestoreOptions.Create() |> setParams let args = project :: buildRestoreArgs param - execWithBinLog project param.Common "restore" args param.MSBuildParams + execWithBinLog project param.Common "restore" args param.MSBuildParams None __.MarkSuccess() /// build configuration @@ -1463,7 +1477,7 @@ module DotNet = use __ = Trace.traceTask "DotNet:pack" project let param = PackOptions.Create() |> setParams let args = project :: buildPackArgs param - execWithBinLog project param.Common "pack" args param.MSBuildParams + execWithBinLog project param.Common "pack" args param.MSBuildParams None __.MarkSuccess() /// @@ -1580,7 +1594,7 @@ module DotNet = use __ = Trace.traceTask "DotNet:publish" project let param = PublishOptions.Create() |> setParams let args = project :: buildPublishArgs param - execWithBinLog project param.Common "publish" args param.MSBuildParams + execWithBinLog project param.Common "publish" args param.MSBuildParams None __.MarkSuccess() /// @@ -1670,7 +1684,7 @@ module DotNet = use __ = Trace.traceTask "DotNet:build" project let param = BuildOptions.Create() |> setParams let args = project :: buildBuildArgs param - execWithBinLog project param.Common "build" args param.MSBuildParams + execWithBinLog project param.Common "build" args param.MSBuildParams None __.MarkSuccess() /// @@ -1821,7 +1835,7 @@ module DotNet = use __ = Trace.traceTask "DotNet:test" project let param = TestOptions.Create() |> setParams let args = project :: buildTestArgs param - execWithBinLog project param.Common "test" args param.MSBuildParams + execWithBinLog project param.Common "test" args param.MSBuildParams param.RunSettingsArguments __.MarkSuccess() let internal buildNugetPushArgs (param: NuGet.NuGetPushParams) = diff --git a/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs b/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs index 9a06719601c..0ee11e0d46f 100644 --- a/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs +++ b/src/test/Fake.Core.UnitTests/Fake.DotNet.Cli.fs @@ -129,4 +129,22 @@ let tests = let expected = "--uninstall my-awesome-template" - Expect.equal cli expected "New --uninstall args generated correctly." ] + Expect.equal cli expected "New --uninstall args generated correctly." + + testCase "Test buildAfterArgs with no after args" + <| fun _ -> + let expected = "hello" + let cli = DotNet.buildAfterArgs [ "hello" ] None |> Args.toWindowsCommandLine + + Expect.equal cli expected "Empty after args." + + testCase "Test buildAfterArgs with after args" + <| fun _ -> + let expected = "hello -- lol=foo" + + let cli = + DotNet.buildAfterArgs [ "hello" ] (Some "lol=foo") |> Args.toWindowsCommandLine + + Expect.equal cli expected "Empty after args." + + ]