diff --git a/.pipelines/PowerShell-Coordinated_Packages-Official.yml b/.pipelines/PowerShell-Coordinated_Packages-Official.yml index 33ec3143a88..5c537781b17 100644 --- a/.pipelines/PowerShell-Coordinated_Packages-Official.yml +++ b/.pipelines/PowerShell-Coordinated_Packages-Official.yml @@ -22,6 +22,10 @@ parameters: displayName: Enable Windows Stage type: boolean default: true + - name: ENABLE_MSBUILD_BINLOGS + displayName: Enable MSBuild Binary Logs + type: boolean + default: false resources: repositories: @@ -68,6 +72,8 @@ variables: value: ${{ parameters.SKIP_SIGNING }} - group: 'AzDevOpsArtifacts' - group: 'mscodehub-feed-read-akv' + - name: ENABLE_MSBUILD_BINLOGS + value: ${{ parameters.ENABLE_MSBUILD_BINLOGS }} extends: template: v2/OneBranch.Official.CrossPlat.yml@onebranchTemplates diff --git a/build.psm1 b/build.psm1 index 39883009bc5..112034fba17 100644 --- a/build.psm1 +++ b/build.psm1 @@ -853,6 +853,10 @@ function Restore-PSPackage $RestoreArguments += "--interactive" } + if ($env:ENABLE_MSBUILD_BINLOGS) { + $RestoreArguments += '-bl' + } + $ProjectDirs | ForEach-Object { $project = $_ Write-Log -message "Run dotnet restore $project $RestoreArguments" @@ -870,6 +874,23 @@ function Restore-PSPackage $retryCount++ if($retryCount -ge $maxTries) { + if ($env:ENABLE_MSBUILD_BINLOGS) { + if ( Test-Path ./msbuild.binlog ) { + if (!(Test-Path $env:OB_OUTPUTDIRECTORY -PathType Container)) { + $null = New-Item -path $env:OB_OUTPUTDIRECTORY -ItemType Directory -Force -Verbose + } + + $projectName = Split-Path -Leaf -Path $project + $binlogFileName = "${projectName}.msbuild.binlog" + if ($IsMacOS) { + $resolvedPath = (Resolve-Path -Path ./msbuild.binlog).ProviderPath + Write-Host "##vso[artifact.upload containerfolder=$binLogFileName;artifactname=$binLogFileName]$resolvedPath" + } else { + Copy-Item -Path ./msbuild.binlog -Destination "$env:OB_OUTPUTDIRECTORY/${projectName}.msbuild.binlog" -Verbose + } + } + } + throw } continue