From 973a6fe91216d0358cec213b6b9926aa711d39a9 Mon Sep 17 00:00:00 2001 From: Vladimir Sumarov Date: Thu, 28 Mar 2024 13:14:16 -0700 Subject: [PATCH] try to try and log --- Build-Dependencies.ps1 | 19 ++++++++++++++++++- utils.pwsh/Setup-Target.ps1 | 32 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Build-Dependencies.ps1 b/Build-Dependencies.ps1 index c0def1de2..4980b1f82 100644 --- a/Build-Dependencies.ps1 +++ b/Build-Dependencies.ps1 @@ -11,9 +11,26 @@ param( [switch] $SkipAll, [switch] $SkipBuild, [switch] $SkipDeps, - [switch] $SkipUnpack + [switch] $SkipUnpack, + [string] $LogFilePath = ".\build_log.txt" # Default log file path ) +# Function to log messages to both console and file +function Log-Message { + param( + [Parameter(Mandatory = $true)] + [string]$Message, + [Parameter(Mandatory = $false)] + [string]$Path = $LogFilePath + ) + + # Write to console + Write-Host $Message + + # Append to log file + $Message | Out-File -FilePath $Path -Append -Encoding UTF8 +} + Set-PSDebug -Trace 1 $ErrorActionPreference = "Stop" diff --git a/utils.pwsh/Setup-Target.ps1 b/utils.pwsh/Setup-Target.ps1 index e3acfd65e..57621968e 100644 --- a/utils.pwsh/Setup-Target.ps1 +++ b/utils.pwsh/Setup-Target.ps1 @@ -79,26 +79,26 @@ function Find-VisualStudio { try { $VisualStudioData = Get-CimInstance -ClassName MSFT_VSInstance -ErrorAction Stop - Write-Output "Successfully retrieved Visual Studio instance data." + Log-Message "Successfully retrieved Visual Studio instance data." } catch { - Write-Output "Failed to retrieve Visual Studio instance data." - Write-Output "Error details: $_" + Log-Message "Failed to retrieve Visual Studio instance data." + Log-Message "Error details: $_" if ($_.Exception.InnerException) { - Write-Output "Inner exception details: $($_.Exception.InnerException.Message)" + Log-Message "Inner exception details: $($_.Exception.InnerException.Message)" } - # Optionally, log additional error properties - Write-Output "Exception Type: $($_.Exception.GetType().FullName)" - Write-Output "Error Message: $($_.Exception.Message)" - Write-Output "Error Category: $($_.CategoryInfo.Category)" - Write-Output "Error Target: $($_.CategoryInfo.TargetName)" - Write-Output "Error Target Type: $($_.CategoryInfo.TargetType)" - # To provide more context, you can include information about the current environment - Write-Output "PowerShell Version: $($PSVersionTable.PSVersion)" - Write-Output "OS Version: $([Environment]::OSVersion)" - # If you're interested in all loaded assemblies, which might be relevant for troubleshooting, uncomment the next line - # Write-Output "Loaded Assemblies: $([AppDomain]::CurrentDomain.GetAssemblies() | Out-String)" + # Log additional error properties + Log-Message "Exception Type: $($_.Exception.GetType().FullName)" + Log-Message "Error Message: $($_.Exception.Message)" + Log-Message "Error Category: $($_.CategoryInfo.Category)" + Log-Message "Error Target: $($_.CategoryInfo.TargetName)" + Log-Message "Error Target Type: $($_.CategoryInfo.TargetType)" + # Environmental context + Log-Message "PowerShell Version: $($PSVersionTable.PSVersion)" + Log-Message "OS Version: $([Environment]::OSVersion)" + # Uncomment if needed + # Log-Message "Loaded Assemblies: $([AppDomain]::CurrentDomain.GetAssemblies() | Out-String)" } - + # Prefer VS versions in this order: # 1. VS2022 Release (stable) # 2. VS2022 Preview