diff --git a/eng/collect_vsinfo.ps1 b/eng/collect_vsinfo.ps1 new file mode 100644 index 00000000000000..0981ae125febce --- /dev/null +++ b/eng/collect_vsinfo.ps1 @@ -0,0 +1,44 @@ +<# +.PARAMETER ArchiveRunName +Name of the run for vs logs + +.NOTES +Returns 0 if succeeds, 1 otherwise +#> +[CmdletBinding(PositionalBinding=$false)] +Param ( + [Parameter(Mandatory=$True)] + [string] $ArchiveRunName +) + +. $PSScriptRoot/common/tools.ps1 + +$vscollect_uri="http://aka.ms/vscollect.exe" +$vscollect="$env:TEMP\vscollect.exe" + +if (-not (Test-Path $vscollect)) { + Retry({ + Write-Host "GET $vscollect_uri" + Invoke-WebRequest $vscollect_uri -OutFile $vscollect -UseBasicParsing + }) + + if (-not (Test-Path $vscollect)) { + Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Unable to download vscollect." + exit 1 + } +} + +&"$vscollect" + +$LogDir = Join-Path $LogDir $ArchiveRunName +mkdir $LogDir +Move-Item $env:TEMP\vslogs.zip "$LogDir" + +$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" +if (-not (Test-Path -Path "$vswhere" -PathType Leaf)) +{ + Write-Error "Couldn't locate vswhere at $vswhere" + exit 1 +} + + &"$vswhere" -all -prerelease -products * | Tee-Object -FilePath "$LogDir\vs_where.log" diff --git a/eng/disable_vsupdate.ps1 b/eng/disable_vsupdate.ps1 new file mode 100644 index 00000000000000..d8d365f0577103 --- /dev/null +++ b/eng/disable_vsupdate.ps1 @@ -0,0 +1,23 @@ +schtasks /change /tn "\Microsoft\VisualStudio\VSIX Auto Update" /disable + +$vswhere = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" +if (-not (Test-Path -Path "$vswhere" -PathType Leaf)) +{ + Write-Error "Couldn't locate vswhere at $vswhere" + exit 1 +} + +$vsdir = &"$vswhere" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath +$vsregedit = "$vsdir\Common7\IDE\VsRegEdit.exe" + +if (-not (Test-Path -Path "$vsregedit" )) +{ + Write-Error "VSWhere returned path: $vsdir, but regedit $vsregedit doesn't exist." + exit 1 +} + +Write-Output "VSWhere returned path: $vsdir, using regedit $vsregedit" +Write-Output "Disabling updates through VS Registry:" + +&"$vsdir\Common7\IDE\VsRegEdit.exe" set local HKCU ExtensionManager AutomaticallyCheckForUpdates2Override dword 0 +&"$vsdir\Common7\IDE\VsRegEdit.exe" read local HKCU ExtensionManager AutomaticallyCheckForUpdates2Override dword diff --git a/eng/native/init-vs-env.cmd b/eng/native/init-vs-env.cmd index 273f49b3392c2d..befe98ab407f72 100644 --- a/eng/native/init-vs-env.cmd +++ b/eng/native/init-vs-env.cmd @@ -26,6 +26,8 @@ if defined VisualStudioVersion goto :VSDetected set "__VSWhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" set "__VSCOMNTOOLS=" +if not exist "%__VSWhere%" goto :VSWhereMissing + if exist "%__VSWhere%" ( for /f "tokens=*" %%p in ( '"%__VSWhere%" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath' @@ -56,6 +58,10 @@ echo %__MsgPrefix%Error: Visual Studio 2022 with C++ tools required. ^ Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build requirements. exit /b 1 +:VSWhereMissing +echo %__MsgPrefix%Error: vswhere couldn not be found in Visual Studio Installer directory at "%__VSWhere%" +exit /b 1 + :SetVCEnvironment if "%__VCBuildArch%"=="" exit /b 0 diff --git a/eng/pipelines/common/global-build-job.yml b/eng/pipelines/common/global-build-job.yml index 41cce9e1534f94..5c731b0745c474 100644 --- a/eng/pipelines/common/global-build-job.yml +++ b/eng/pipelines/common/global-build-job.yml @@ -148,6 +148,13 @@ jobs: clean: true fetchDepth: $(checkoutFetchDepth) + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/disable_vsupdate.ps1 + ./eng/collect_vsinfo.ps1 -ArchiveName initialization_log + displayName: Collect vslogs on Entry and disable updates + condition: always() + - ${{ if and(eq(parameters.isOfficialBuild, true), notin(parameters.osGroup, 'osx', 'maccatalyst', 'ios', 'iossimulator', 'tvos', 'tvossimulator')) }}: - template: /eng/pipelines/common/restore-internal-tools.yml @@ -229,6 +236,11 @@ jobs: shouldContinueOnError: ${{ parameters.shouldContinueOnError }} ${{ insert }}: ${{ parameters.extraStepsParameters }} + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/collect_vsinfo.ps1 -ArchiveName postbuild_log + displayName: Collect vslogs on exit + - task: PublishBuildArtifacts@1 displayName: Publish Logs inputs: diff --git a/eng/pipelines/coreclr/templates/build-job.yml b/eng/pipelines/coreclr/templates/build-job.yml index cce7b6f7cf1e71..f17b54eb844a2b 100644 --- a/eng/pipelines/coreclr/templates/build-job.yml +++ b/eng/pipelines/coreclr/templates/build-job.yml @@ -126,6 +126,13 @@ jobs: - ${{ parameters.variables }} steps: + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/disable_vsupdate.ps1 + ./eng/collect_vsinfo.ps1 -ArchiveName initialization_log + displayName: Collect vslogs on Entry and disable updates + condition: always() + # Install native dependencies # Linux builds use docker images with dependencies preinstalled, @@ -275,6 +282,13 @@ jobs: parameters: name: ${{ parameters.platform }} + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/collect_vsinfo.ps1 -ArchiveName postbuild_log + displayName: Collect vslogs on exit + condition: always() + + # Publish Logs - task: PublishPipelineArtifact@1 displayName: Publish Logs diff --git a/eng/pipelines/installer/jobs/build-job.yml b/eng/pipelines/installer/jobs/build-job.yml index f7f1b27b69fd90..641a5452f4b38d 100644 --- a/eng/pipelines/installer/jobs/build-job.yml +++ b/eng/pipelines/installer/jobs/build-job.yml @@ -305,6 +305,13 @@ jobs: clean: true fetchDepth: $(checkoutFetchDepth) + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/disable_vsupdate.ps1 + ./eng/collect_vsinfo.ps1 -ArchiveName initialization_log + displayName: Collect vslogs on Entry and disable updates + condition: always() + - ${{ if ne(variables['System.TeamProject'], 'public') }}: - ${{ if ne(parameters.osGroup, 'windows') }}: - task: Bash@3 @@ -376,6 +383,13 @@ jobs: displayName: Build and Package continueOnError: ${{ and(eq(variables.SkipTests, false), eq(parameters.shouldContinueOnError, true)) }} + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/collect_vsinfo.ps1 -ArchiveName postbuild_log + displayName: Collect vslogs on exit + condition: always() + + - ${{ if in(parameters.osGroup, 'osx', 'ios', 'tvos') }}: - script: | du -sh $(Build.SourcesDirectory)/* diff --git a/eng/pipelines/mono/templates/build-job.yml b/eng/pipelines/mono/templates/build-job.yml index 845078804fbc7f..8db3b17fc34dc3 100644 --- a/eng/pipelines/mono/templates/build-job.yml +++ b/eng/pipelines/mono/templates/build-job.yml @@ -138,6 +138,13 @@ jobs: df -h displayName: Disk Usage before Build + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/disable_vsupdate.ps1 + ./eng/collect_vsinfo.ps1 -ArchiveName initialization_log + displayName: Collect vslogs on Entry and disable updates + condition: always() + # Build - ${{ if ne(parameters.osGroup, 'windows') }}: - script: ./build$(scriptExt) -subset mono+clr.hosts $(crossArg) -c $(buildConfig) -arch $(archType) $(osOverride) -ci $(officialBuildIdArg) $(aotCrossParameter) $(llvmParameter) $(darwinFrameworks) @@ -171,6 +178,11 @@ jobs: - script: build$(scriptExt) -subset mono+clr.hosts -c $(buildConfig) -arch $(archType) $(osOverride) -ci $(officialBuildIdArg) $(aotCrossParameter) $(llvmParameter) -pack $(OutputRidArg) displayName: Build nupkg + - ${{ if eq(parameters.osGroup, 'windows') }}: + - powershell: | + ./eng/collect_vsinfo.ps1 -ArchiveName postbuild_log + displayName: Collect vslogs on exit + condition: always() # Publish Logs - task: PublishPipelineArtifact@1 displayName: Publish Logs