From 4521fb84f8b0f950f6b77e32fdd914fe53ea09fb Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Tue, 23 Jan 2024 13:20:19 +0100 Subject: [PATCH] Fixes #3302 (#3303) Issue warning and errors if settings in the settings file doesn't exist or are of a wrong type Change setting, which was of a wrong type --------- Co-authored-by: freddydk --- BC.HelperFunctions.ps1 | 28 +++++++++++++++---- .../Compile-AppWithBcCompilerFolder.ps1 | 2 +- .../New-BcCompilerFolder.ps1 | 4 +-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/BC.HelperFunctions.ps1 b/BC.HelperFunctions.ps1 index b3417786f..916a1d46b 100644 --- a/BC.HelperFunctions.ps1 +++ b/BC.HelperFunctions.ps1 @@ -20,7 +20,8 @@ function Get-ContainerHelperConfig { "useVolumes" = $false "useVolumeForMyFolder" = $false "use7zipIfAvailable" = $true - "defaultNewContainerParameters" = @{ } + "defaultNewContainerParameters" = [PSCustomObject]@{ + } "hostHelperFolder" = "" "containerHelperFolder" = $programDataFolder "defaultContainerName" = "bcserver" @@ -99,7 +100,7 @@ function Get-ContainerHelperConfig { "RenewClientContextBetweenTests" = $false "DebugMode" = $false "DoNotUseCdnForArtifacts" = $false - "MinimumDotNetRuntimeVersion" = [System.Version]"6.0.16" + "MinimumDotNetRuntimeVersionStr" = "6.0.16" "MinimumDotNetRuntimeVersionUrl" = 'https://download.visualstudio.microsoft.com/download/pr/ca13c6f1-3107-4cf8-991c-f70edc1c1139/a9f90579d827514af05c3463bed63c22/dotnet-sdk-6.0.408-win-x64.zip' "AlpacaSettings" = [PSCustomObject]@{ "BaseUrl" = "https://cosmo-alpaca-enterprise.westeurope.cloudapp.azure.com" @@ -128,15 +129,30 @@ function Get-ContainerHelperConfig { try { $savedConfig = Get-Content $configFile | ConvertFrom-Json if ("$savedConfig") { - $keys = $bcContainerHelperConfig.Keys | % { $_ } + $keys = $bcContainerHelperConfig.Keys | ForEach-Object { $_ } $keys | ForEach-Object { if ($savedConfig.PSObject.Properties.Name -eq "$_") { - if (!$silent) { - Write-Host "Setting $_ = $($savedConfig."$_")" + if ($bcContainerHelperConfig."$_" -and $savedConfig."$_" -and $bcContainerHelperConfig."$_".GetType() -ne $savedConfig."$_".GetType()) { + Write-Host -ForegroundColor Red "Ignoring config setting $_ as the type in the config file is different than in the default configuration" + } + else { + if ((ConvertTo-Json -InputObject $bcContainerHelperConfig."$_" -Compress) -eq (ConvertTo-Json -InputObject $savedConfig."$_" -Compress)) { + if (!$silent) { + Write-Host "Ignoring unchanged config setting $_" + } + } + else { + if (!$silent) { + Write-Host "Setting $_ = $($savedConfig."$_")" + } + $bcContainerHelperConfig."$_" = $savedConfig."$_" + } } - $bcContainerHelperConfig."$_" = $savedConfig."$_" } } + $savedConfig.PSObject.Properties.Name | Where-Object { $keys -notcontains $_ } | ForEach-Object { + Write-Host -ForegroundColor Yellow "Ignoring unknown config setting $_" + } } } catch { diff --git a/CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1 b/CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1 index 3515f015a..b203d0bd1 100644 --- a/CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1 +++ b/CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1 @@ -304,7 +304,7 @@ try { $probingPaths = @((Join-Path $dllsPath "OpenXML")) + $probingPaths } elseif ($platformversion.Major -ge 22) { - if ($dotNetRuntimeVersionInstalled -ge $bcContainerHelperConfig.MinimumDotNetRuntimeVersion) { + if ($dotNetRuntimeVersionInstalled -ge [System.Version]$bcContainerHelperConfig.MinimumDotNetRuntimeVersionStr) { $probingPaths = @((Join-Path $dllsPath "OpenXML"), "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\$dotNetRuntimeVersionInstalled", "C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\$dotNetRuntimeVersionInstalled") + $probingPaths } else { diff --git a/CompilerFolderHandling/New-BcCompilerFolder.ps1 b/CompilerFolderHandling/New-BcCompilerFolder.ps1 index 0c096056c..9a53592fc 100644 --- a/CompilerFolderHandling/New-BcCompilerFolder.ps1 +++ b/CompilerFolderHandling/New-BcCompilerFolder.ps1 @@ -165,12 +165,12 @@ try { } $dotNetSharedFolder = Join-Path $dllsPath 'shared' - if ($version -ge "22.0.0.0" -and (!(Test-Path $dotNetSharedFolder)) -and ($dotNetRuntimeVersionInstalled -lt $bcContainerHelperConfig.MinimumDotNetRuntimeVersion)) { + if ($version -ge "22.0.0.0" -and (!(Test-Path $dotNetSharedFolder)) -and ($dotNetRuntimeVersionInstalled -lt [System.Version]$bcContainerHelperConfig.MinimumDotNetRuntimeVersionStr)) { if ("$dotNetRuntimeVersionInstalled" -eq "0.0.0") { Write-Host "dotnet runtime version is not installed/cannot be used" } else { - Write-Host "dotnet runtime version $dotNetRuntimeVersionInstalled is installed, but minimum required version is $($bcContainerHelperConfig.MinimumDotNetRuntimeVersion)" + Write-Host "dotnet runtime version $dotNetRuntimeVersionInstalled is installed, but minimum required version is $($bcContainerHelperConfig.MinimumDotNetRuntimeVersionStr)" } Write-Host "Downloading minimum required dotnet version from $($bcContainerHelperConfig.MinimumDotNetRuntimeVersionUrl)" $dotnetFolder = Join-Path $compilerFolder 'dotnet'