Skip to content

Commit

Permalink
Add logFileVerbosity to MSBuild and VSBuild tasks (#9091)
Browse files Browse the repository at this point in the history
Similar to VSTest task. Fixes #7823.
  • Loading branch information
heaths authored and moswald committed Jan 15, 2019
1 parent ccdc046 commit e52c2bb
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 23 deletions.
18 changes: 16 additions & 2 deletions Tasks/Common/MSBuildHelpers/InvokeFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function Invoke-BuildTools {
[string]$MSBuildArguments,
[switch]$Clean,
[switch]$NoTimelineLogger,
[switch]$CreateLogFile)
[switch]$CreateLogFile,
[string]$LogFileVerbosity)

Trace-VstsEnteringInvocation $MyInvocation
try {
Expand All @@ -25,6 +26,10 @@ function Invoke-BuildTools {
$splat["LogFile"] = "$file-clean.log"
}

if ($LogFileVerbosity) {
$splat["LogFileVerbosity"] = $LogFileVerbosity
}

Invoke-MSBuild -ProjectFile $file -Targets Clean -MSBuildPath $MSBuildLocation -AdditionalArguments $MSBuildArguments -NoTimelineLogger:$NoTimelineLogger @splat
}

Expand All @@ -33,6 +38,10 @@ function Invoke-BuildTools {
$splat["LogFile"] = "$file.log"
}

if ($LogFileVerbosity) {
$splat["LogFileVerbosity"] = $LogFileVerbosity
}

Invoke-MSBuild -ProjectFile $file -MSBuildPath $MSBuildLocation -AdditionalArguments $MSBuildArguments -NoTimelineLogger:$NoTimelineLogger @splat
}
} finally {
Expand All @@ -50,6 +59,7 @@ function Invoke-MSBuild {
[string]$ProjectFile,
[string]$Targets,
[string]$LogFile,
[string]$LogFileVerbosity,
[switch]$NoTimelineLogger,
[string]$MSBuildPath, # TODO: Switch MSBuildPath to mandatory. Both callers (MSBuild and VSBuild task) throw prior to reaching here if MSBuild cannot be resolved.
[string]$AdditionalArguments)
Expand Down Expand Up @@ -80,7 +90,7 @@ function Invoke-MSBuild {

# If a log file was specified then hook up the default file logger.
if ($LogFile) {
$arguments = "$arguments /fl /flp:`"logfile=$LogFile`""
$arguments = "$arguments /fl /flp:`"logfile=$LogFile;verbosity=$LogFileVerbosity`""
}

# Start the detail timeline.
Expand Down Expand Up @@ -124,6 +134,10 @@ function Invoke-MSBuild {
$detailFinishTime = [datetime]::UtcNow.ToString('O')
Write-VstsLogDetail -Id $detailId -FinishTime $detailFinishTime -Progress 100 -State Completed -Result $detailResult -AsOutput
}

if ($LogFile) {
Write-Host "##vso[task.uploadfile]$LogFile"
}
}
} finally {
Trace-VstsLeavingInvocation $MyInvocation
Expand Down
8 changes: 6 additions & 2 deletions Tasks/MSBuildV1/MSBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Trace-VstsEnteringInvocation $MyInvocation
try {
Import-VstsLocStrings "$PSScriptRoot\Task.json"

# Get task variables.
[bool]$debug = Get-VstsTaskVariable -Name System.Debug -AsBool

# Get the inputs.
[string]$msBuildLocationMethod = Get-VstsInput -Name MSBuildLocationMethod
[string]$msBuildLocation = Get-VstsInput -Name MSBuildLocation
Expand All @@ -16,7 +19,8 @@ try {
[bool]$maximumCpuCount = Get-VstsInput -Name MaximumCpuCount -AsBool
[bool]$restoreNuGetPackages = Get-VstsInput -Name RestoreNuGetPackages -AsBool
[bool]$logProjectEvents = Get-VstsInput -Name LogProjectEvents -AsBool
[bool]$createLogFile = Get-VstsInput -Name CreateLogFile -AsBool
[bool]$createLogFile = (Get-VstsInput -Name CreateLogFile -AsBool) -or $debug
[string]$logFileVerbosity = if ($debug) { "diagnostic" } else { Get-VstsInput -Name LogFileVerbosity }
[string]$msBuildVersion = Get-VstsInput -Name MSBuildVersion
[string]$msBuildArchitecture = Get-VstsInput -Name MSBuildArchitecture

Expand All @@ -40,7 +44,7 @@ try {
$global:ErrorActionPreference = 'Continue'

# Build each solution.
Invoke-BuildTools -NuGetRestore:$restoreNuGetPackages -SolutionFiles $solutionFiles -MSBuildLocation $msBuildLocation -MSBuildArguments $msBuildArguments -Clean:$clean -NoTimelineLogger:(!$logProjectEvents) -CreateLogFile:$createLogFile
Invoke-BuildTools -NuGetRestore:$restoreNuGetPackages -SolutionFiles $solutionFiles -MSBuildLocation $msBuildLocation -MSBuildArguments $msBuildArguments -Clean:$clean -NoTimelineLogger:(!$logProjectEvents) -CreateLogFile:$createLogFile -LogFileVerbosity:$logFileVerbosity
} finally {
Trace-VstsLeavingInvocation $MyInvocation
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"loc.input.help.logProjectEvents": "Optionally record timeline details for each project (Windows only).",
"loc.input.label.createLogFile": "Create Log File",
"loc.input.help.createLogFile": "Optionally create a log file (Windows only).",
"loc.input.label.logFileVerbosity": "Log File Verbosity",
"loc.input.help.logFileVerbosity": "Optional log file verbosity.",
"loc.messages.RecordProjectDetailsOnlySupportedOnWindows": "`Record Project Details` is only supported on Windows.",
"loc.messages.CreateLogFileOnlySupportedOnWindows": "`Create Log File` is only supported on Windows.",
"loc.messages.MSB_BuildToolNotFound": "MSBuild or xbuild (Mono) were not found on the macOS or Linux agent."
Expand Down
23 changes: 16 additions & 7 deletions Tasks/MSBuildV1/Tests/PassesArguments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ Register-Mock Trace-VstsEnteringInvocation
Register-Mock Trace-VstsLeavingInvocation
Register-Mock Import-VstsLocStrings
$variableSets = @(
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $true ; CreateLogFile = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $true ; LogProjectEvents = $false ; CreateLogFile = $false }
@{ Clean = $false ; MaximumCpuCount = $true ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $true ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $true ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $true ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNuGetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $true }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNuGetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = 'detailed' ; Debug = $false }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNuGetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = 'detailed' ; Debug = $true }
)
foreach ($variableSet in $variableSets) {
Unregister-Mock Get-VstsInput
Unregister-Mock Get-VstsTaskVariable
Unregister-Mock Get-SolutionFiles
Unregister-Mock Format-MSBuildArguments
Unregister-Mock Select-MSBuildPath
Expand All @@ -33,15 +37,20 @@ foreach ($variableSet in $variableSets) {
Register-Mock Get-VstsInput { $variableSet.CreateLogFile } -- -Name CreateLogFile -AsBool
Register-Mock Get-VstsInput { 'Some input version' } -- -Name MSBuildVersion
Register-Mock Get-VstsInput { 'Some input architecture' } -- -Name MSBuildArchitecture
Register-Mock Get-VstsInput { $variableSet.LogFileVerbosity } -- -Name LogFileVerbosity
Register-Mock Get-VstsTaskVariable { $variableSet.Debug } -- -Name System.Debug -AsBool
Register-Mock Get-SolutionFiles { 'Some solution 1', 'Some solution 2' } -- -Solution 'Some input solution'
Register-Mock Format-MSBuildArguments { 'Some formatted arguments' } -- -MSBuildArguments 'Some input arguments' -Platform 'Some input platform' -Configuration 'Some input configuration' -MaximumCpuCount: $variableSet.MaximumCpuCount
Register-Mock Select-MSBuildPath { 'Some location' } -- -Method 'Some input method' -Location 'Some input location' -PreferredVersion 'Some input version' -Architecture 'Some input architecture'
Register-Mock Invoke-BuildTools { 'Some build output line 1', 'Some build output line 2' }

$ExpectedCreateLogFile = if ($variableSet.Debug) { $true } else { $variableSet.CreateLogFile }
$ExpectedLogFileVerbosity = if ($variableSet.Debug) { 'diagnostic' } else { $variableSet.LogFileVerbosity }

# Act.
$output = & $PSScriptRoot\..\MSBuild.ps1

# Assert.
Assert-AreEqual ('Some build output line 1', 'Some build output line 2') $output
Assert-WasCalled Invoke-BuildTools -- -NuGetRestore: $variableSet.RestoreNuGetPackages -SolutionFiles @('Some solution 1', 'Some solution 2') -MSBuildLocation 'Some location' -MSBuildArguments 'Some formatted arguments' -Clean: $variableSet.Clean -NoTimelineLogger: $(!$variableSet.LogProjectEvents) -CreateLogFile: $variableSet.CreateLogFile
Assert-WasCalled Invoke-BuildTools -- -NuGetRestore: $variableSet.RestoreNuGetPackages -SolutionFiles @('Some solution 1', 'Some solution 2') -MSBuildLocation 'Some location' -MSBuildArguments 'Some formatted arguments' -Clean: $variableSet.Clean -NoTimelineLogger: $(!$variableSet.LogProjectEvents) -CreateLogFile: $ExpectedCreateLogFile -LogFileVerbosity: $ExpectedLogFileVerbosity
}
19 changes: 18 additions & 1 deletion Tasks/MSBuildV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 146,
"Minor": 147,
"Patch": 0
},
"demands": [
Expand Down Expand Up @@ -149,6 +149,23 @@
"required": false,
"helpMarkDown": "Optionally create a log file (Windows only).",
"groupName": "advanced"
},
{
"name": "logFileVerbosity",
"type": "pickList",
"label": "Log File Verbosity",
"defaultValue": "normal",
"required": false,
"helpMarkDown": "Optional log file verbosity.",
"groupName": "advanced",
"options": {
"quiet": "Quiet",
"minimal": "Minimal",
"normal": "Normal",
"detailed": "Detailed",
"diagnostic": "Diagnostic"
},
"visibleRule": "createLogFile = true"
}
],
"instanceNameFormat": "Build solution $(solution)",
Expand Down
19 changes: 18 additions & 1 deletion Tasks/MSBuildV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 120,
"Minor": 147,
"Patch": 0
},
"demands": [
Expand Down Expand Up @@ -148,6 +148,23 @@
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.createLogFile",
"groupName": "advanced"
},
{
"name": "logFileVerbosity",
"type": "pickList",
"label": "ms-resource:loc.input.label.logFileVerbosity",
"defaultValue": "normal",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.logFileVerbosity",
"groupName": "advanced",
"options": {
"quiet": "Quiet",
"minimal": "Minimal",
"normal": "Normal",
"detailed": "Detailed",
"diagnostic": "Diagnostic"
},
"visibleRule": "createLogFile = true"
}
],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"loc.input.help.logProjectEvents": "Optionally record timeline details for each project.",
"loc.input.label.createLogFile": "Create Log File",
"loc.input.help.createLogFile": "Optionally create a log file (Windows only).",
"loc.input.label.logFileVerbosity": "Log File Verbosity",
"loc.input.help.logFileVerbosity": "Optional log file verbosity.",
"loc.messages.MSBuildLocationDeprecated0": "The MSBuild location parameter has been deprecated. Ignoring value '{0}'",
"loc.messages.MSBuildVersionDeprecated0": "The MSBuild version parameter has been deprecated. Ignoring value '{0}'.",
"loc.messages.UnexpectedVSVersion0": "Unexpected Visual Studio version '{0}'.",
Expand Down
1 change: 1 addition & 0 deletions Tasks/VSBuildV1/Tests/MapsVSVersions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
Register-Mock Get-VstsTaskVariable { $false } -- -Name System.Debug -AsBool
Register-Mock Get-SolutionFiles
Register-Mock Format-MSBuildArguments
Register-Mock Invoke-BuildTools
Expand Down
21 changes: 15 additions & 6 deletions Tasks/VSBuildV1/Tests/PassesArguments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ param()
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
$variableSets = @(
# Variable combinations to assert Booleans are passed correctly.
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $true ; CreateLogFile = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $true ; LogProjectEvents = $false ; CreateLogFile = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $true ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; VSVersion = '14.0' }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $true ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $false ; RestoreNugetPackages = $true ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $false ; MaximumCpuCount = $true ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $false ; LogFileVerbosity = '' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = 'detailed' ; Debug = $false ; VSVersion = '14.0' }
@{ Clean = $true ; MaximumCpuCount = $false ; RestoreNugetPackages = $false ; LogProjectEvents = $false ; CreateLogFile = $true ; LogFileVerbosity = 'detailed' ; Debug = $true ; VSVersion = '14.0' }
)
foreach ($variableSet in $variableSets) {
Unregister-Mock Get-VstsInput
Unregister-Mock Get-VstsTaskVariable
Unregister-Mock Get-SolutionFiles
Unregister-Mock Select-VSVersion
Unregister-Mock Select-MSBuildPath
Expand All @@ -29,16 +33,21 @@ foreach ($variableSet in $variableSets) {
Register-Mock Get-VstsInput { $variableSet.RestoreNuGetPackages } -- -Name RestoreNuGetPackages -AsBool
Register-Mock Get-VstsInput { $variableSet.LogProjectEvents } -- -Name LogProjectEvents -AsBool
Register-Mock Get-VstsInput { $variableSet.CreateLogFile } -- -Name CreateLogFile -AsBool
Register-Mock Get-VstsInput { $variableSet.LogFileVerbosity } -- -Name LogFileVerbosity
Register-Mock Get-VstsTaskVariable { $variableSet.Debug } -- -Name System.Debug -AsBool
Register-Mock Get-SolutionFiles { 'Some solution 1', 'Some solution 2' } -- -Solution 'Some input solution'
Register-Mock Select-VSVersion { $variableSet.VSVersion } -- -PreferredVersion $variableSet.VSVersion
Register-Mock Select-MSBuildPath { 'Some MSBuild location' } -- -PreferredVersion $variableSet.VSVersion -Architecture 'Some input architecture'
Register-Mock Format-MSBuildArguments { 'Some formatted arguments' } -- -MSBuildArguments 'Some input arguments' -Platform 'Some input platform' -Configuration 'Some input configuration' -VSVersion $variableSet.VSVersion -MaximumCpuCount: $variableSet.MaximumCpuCount
Register-Mock Invoke-BuildTools { 'Some build output' }

$ExpectedCreateLogFile = if ($variableSet.Debug) { $true } else { $variableSet.CreateLogFile }
$ExpectedLogFileVerbosity = if ($variableSet.Debug) { 'diagnostic' } else { $variableSet.LogFileVerbosity }

# Act.
$output = & $PSScriptRoot\..\VSBuild.ps1

# Assert.
Assert-AreEqual 'Some build output' $output
Assert-WasCalled Invoke-BuildTools -- -NuGetRestore: $variableSet.RestoreNuGetPackages -SolutionFiles @('Some solution 1', 'Some solution 2') -MSBuildLocation 'Some MSBuild location' -MSBuildArguments 'Some formatted arguments' -Clean: $variableSet.Clean -NoTimelineLogger: $(!$variableSet.LogProjectEvents) -CreateLogFile: $variableSet.CreateLogFile
Assert-WasCalled Invoke-BuildTools -- -NuGetRestore: $variableSet.RestoreNuGetPackages -SolutionFiles @('Some solution 1', 'Some solution 2') -MSBuildLocation 'Some MSBuild location' -MSBuildArguments 'Some formatted arguments' -Clean: $variableSet.Clean -NoTimelineLogger: $(!$variableSet.LogProjectEvents) -CreateLogFile: $ExpectedCreateLogFile -LogFileVerbosity: $ExpectedLogFileVerbosity
}
1 change: 1 addition & 0 deletions Tasks/VSBuildV1/Tests/ThrowsIfUnknownVSVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Register-Mock Get-VstsInput { $false } -- -Name MaximumCpuCount -AsBool
Register-Mock Get-VstsInput { $false } -- -Name RestoreNuGetPackages -AsBool
Register-Mock Get-VstsInput { $false } -- -Name LogProjectEvents -AsBool
Register-Mock Get-VstsInput { $false } -- -Name CreateLogFile -AsBool
Register-Mock Get-VstsTaskVariable { $false } -- -Name System.Debug -AsBool
Register-Mock Select-VSVersion { 'nosuchversion' } -- -PreferredVersion '14.0'
Register-Mock Select-MSBuildPath
Register-Mock Format-MSBuildArguments
Expand Down
1 change: 1 addition & 0 deletions Tasks/VSBuildV1/Tests/WarnsIfDeprecatedInputSpecified.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ foreach ($variableSet in $variableSets) {
Register-Mock Get-VstsInput { $variableSet.MSBuildVersion } -- -Name MSBuildVersion
}
Register-Mock Get-SolutionFiles
Register-Mock Get-VstsTaskVariable { $false } -- -Name System.Debug -AsBool
Register-Mock Select-VSVersion
Register-Mock Select-MSBuildPath
Register-Mock Format-MSBuildArguments
Expand Down
Loading

0 comments on commit e52c2bb

Please sign in to comment.