Skip to content

Commit 40b6de5

Browse files
add support for /tl:[auto|on|off] msbuild flag (#2768)
* add support for /tl:[auto|on|off] msbuild flag * adjust link to PR * wrap help text in <para/> tags for better rendering in IDE --------- Co-authored-by: Andrii Chebukin <XperiAndri@Outlook.com>
1 parent 0145d17 commit 40b6de5

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 6.0.1 - 2024-07-11
44
* BUGFIX: MSBuild.build adds a bad string at the end of properties, thanks @0x53A - https://github.com/fsprojects/FAKE/issues/2738
55
* ENHANCEMENT: Added shorthash to git functions, thanks @voronoipotato - https://github.com/fsprojects/FAKE/pull/2752
6+
* ENHANCEMENT: Support for `/tl:[auto:on:off]` msbuild flag, thanks @smoothdeveloper - https://github.com/fsprojects/FAKE/pull/2768
67
* ENHANCEMENT: Fixes for usage in .NET 8.0 enviroment projects.
78

89
## 6.0.0 - 2023-02-20

src/app/Fake.DotNet.MSBuild/MSBuild.fs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ type MSBuildVerbosity =
3333
| Detailed
3434
| Diagnostic
3535

36+
/// <summary>
37+
/// <para>Specifies whether the terminal logger should be used for the build output. The default is auto, which first verifies the environment before enabling terminal logging. The environment check verifies that the terminal is capable of using modern output features and isn't using a redirected standard output before enabling the new logger. on skips the environment check and enables terminal logging. off skips the environment check and uses the default console logger.</para>
38+
/// <para>The terminal logger shows you the restore phase followed by the build phase. During each phase, the currently building projects appear at the bottom of the terminal. Each project that's building outputs both the MSBuild target currently being built and the amount of time spent on that target. You can search this information to learn more about the build. When a project is finished building, a single "build completed" section is written that captures:</para>
39+
/// <para>
40+
/// <ul>
41+
/// <li>The name of the built project.</li>
42+
/// <li>The target framework (if multi-targeted).</li>
43+
/// <li>The status of that build.</li>
44+
/// <li>The primary output of that build (which is hyperlinked).</li>
45+
/// <li>Any diagnostics generated for that project.</li>
46+
/// </ul>
47+
/// </para>
48+
/// </summary>
49+
/// <remarks>This option is available starting in .NET 8.</remarks>
50+
[<RequireQualifiedAccess>]
51+
type MSBuildTerminalLoggerOption =
52+
| On
53+
| Off
54+
| Auto
55+
3656
/// <summary>
3757
/// MSBuild log option
3858
/// See <a href="https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2015">
@@ -414,6 +434,9 @@ type MSBuildParams =
414434
/// Disable the default console logger, and don't log events to the console.
415435
NoConsoleLogger: bool
416436

437+
/// --tl[auto|on|off]
438+
TerminalLogger: MSBuildTerminalLoggerOption
439+
417440
/// The list of warnings to treat as errors
418441
WarnAsError: string list option
419442

@@ -455,6 +478,7 @@ type MSBuildParams =
455478
ToolsVersion = None
456479
Verbosity = None
457480
NoConsoleLogger = false
481+
TerminalLogger = MSBuildTerminalLoggerOption.Auto
458482
WarnAsError = None
459483
NoWarn = None
460484
RestorePackagesFlag = false
@@ -529,6 +553,9 @@ module MSBuild =
529553
/// Disable the default console logger, and don't log events to the console.
530554
NoConsoleLogger: bool
531555

556+
/// --tl:[auto|on|off]
557+
TerminalLogger: MSBuildTerminalLoggerOption
558+
532559
/// The list of warnings to treat as errors
533560
WarnAsError: string list option
534561

@@ -565,6 +592,7 @@ module MSBuild =
565592
ToolsVersion = None
566593
Verbosity = None
567594
NoConsoleLogger = false
595+
TerminalLogger = MSBuildTerminalLoggerOption.Auto
568596
WarnAsError = None
569597
NoWarn = None
570598
DisableInternalBinLog = false
@@ -588,6 +616,7 @@ module MSBuild =
588616
ToolsVersion = x.ToolsVersion
589617
Verbosity = x.Verbosity
590618
NoConsoleLogger = x.NoConsoleLogger
619+
TerminalLogger = x.TerminalLogger
591620
WarnAsError = x.WarnAsError
592621
NoWarn = x.NoWarn
593622
DisableInternalBinLog = x.DisableInternalBinLog
@@ -614,6 +643,7 @@ module MSBuild =
614643
ToolsVersion = x.ToolsVersion
615644
Verbosity = x.Verbosity
616645
NoConsoleLogger = x.NoConsoleLogger
646+
TerminalLogger = x.TerminalLogger
617647
WarnAsError = x.WarnAsError
618648
NoWarn = x.NoWarn
619649
Loggers = x.Loggers
@@ -859,6 +889,11 @@ module MSBuild =
859889
yield maxCpu
860890
yield noLogo
861891
yield nodeReuse
892+
yield
893+
(match p.TerminalLogger with
894+
| MSBuildTerminalLoggerOption.Off -> Some("tl", "off")
895+
| MSBuildTerminalLoggerOption.On -> Some("tl", "on")
896+
| MSBuildTerminalLoggerOption.Auto -> None)
862897
yield tools
863898
yield verbosity
864899
yield noConsoleLogger

src/test/Fake.Core.UnitTests/Fake.DotNet.MSBuild.fs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ open Expecto
66

77
[<Tests>]
88
let tests =
9+
let flagsTestCase name changeBuildArgs expected =
10+
testCase name
11+
<| fun _ ->
12+
let _, cmdLine = MSBuild.buildArgs changeBuildArgs
13+
14+
let expected =
15+
if BuildServer.ansiColorSupport then
16+
$"%s{expected} /clp:ForceConsoleColor".Trim()
17+
else
18+
expected.Trim()
19+
20+
let expected =
21+
if Environment.isUnix then
22+
$"{expected} /p:RestorePackages=False".Trim()
23+
else
24+
$"/m /nodeReuse:False {expected} /p:RestorePackages=False".Trim()
25+
26+
Expect.equal cmdLine expected $"Expected a given cmdLine '{expected}', but got '{cmdLine}'."
27+
928
testList
1029
"Fake.DotNet.MSBuild.Tests"
1130
[ testCase "Test that we can create simple msbuild cmdline"
@@ -37,4 +56,18 @@ let tests =
3756
else
3857
"/restore /m /nodeReuse:False /p:RestorePackages=False"
3958

40-
Expect.equal cmdLine expected "Expected a given cmdline." ]
59+
Expect.equal cmdLine expected "Expected a given cmdline."
60+
61+
flagsTestCase "/tl:auto doesn't ouput anything (1)" id ""
62+
flagsTestCase
63+
"/tl:auto doesn't ouput anything (2)"
64+
(fun args -> { args with TerminalLogger = MSBuildTerminalLoggerOption.Auto })
65+
""
66+
flagsTestCase
67+
"/tl:on does ouput"
68+
(fun args -> { args with TerminalLogger = MSBuildTerminalLoggerOption.On })
69+
"/tl:on"
70+
flagsTestCase
71+
"/tl:off does ouput"
72+
(fun args -> { args with TerminalLogger = MSBuildTerminalLoggerOption.Off })
73+
"/tl:off" ]

0 commit comments

Comments
 (0)