diff --git a/Actions/.Modules/ReadSettings.psm1 b/Actions/.Modules/ReadSettings.psm1 index ec6dc5588..99e47fd1f 100644 --- a/Actions/.Modules/ReadSettings.psm1 +++ b/Actions/.Modules/ReadSettings.psm1 @@ -595,23 +595,16 @@ function ValidateSettings { $settings ) Process { + if ($PSVersionTable.PSVersion.Major -lt 7) { + return + } + $settingsJson = ConvertTo-Json -InputObject $settings -Depth 99 -Compress $settingsSchemaFile = Join-Path $PSScriptRoot "settings.schema.json" -Resolve $result = "" try{ - $command = [scriptblock] { - $result = '' - Test-Json -Json $args[0] -SchemaFile $args[1] -ErrorVariable result -ErrorAction SilentlyContinue | Out-Null - return $result - } - - if($PSVersionTable.PSVersion.Major -lt 6) { # Test-Json is not available in PS5.1 - $result = pwsh -noprofile -Command $command -args $settingsJson, $settingsSchemaFile - } - else { - $result = Invoke-Command -ScriptBlock $command -ArgumentList $settingsJson, $settingsSchemaFile - } + Test-Json -Json $settingsJson -SchemaFile $settingsSchemaFile -ErrorVariable result -ErrorAction SilentlyContinue | Out-Null } catch { OutputWarning "Error validating settings. Error: $($_.Exception.Message)" diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 0c0302d91..66be5d899 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -45,6 +45,7 @@ The `DownloadProjectDependencies` action now downloads only artifacts from depen - Issue 2204 - Workspace compilation ignores vsixFile setting - Issue 2211 - Cannot create a release if a project contains only test apps - Issue 2214 - Workspace compilation not working with external dependencies +- Fix "filename or extension is too long" error when validating settings on PS5.1 with large settings JSON - Issue 2235 - Workspace compilation: only the first `customCodeCops` entry resolved when multiple relative paths were configured. Relative `customCodeCops` paths are now resolved against the project folder before being passed to the compiler. ## v9.0 diff --git a/Tests/ReadSettings.Test.ps1 b/Tests/ReadSettings.Test.ps1 index 569a9bcb6..c38a7f03a 100644 --- a/Tests/ReadSettings.Test.ps1 +++ b/Tests/ReadSettings.Test.ps1 @@ -540,5 +540,28 @@ InModuleScope ReadSettings { # Allows testing of private functions Pop-Location Remove-Item -Path $tempName -Recurse -Force } + + It 'ValidateSettings skips validation entirely on PS versions less than 7 without warning' { + Mock OutputWarning { } + + $settings = @{ "someProp" = "someValue" } + + if ($PSVersionTable.PSVersion.Major -ge 7) { + # On PS7+, the Invoke-Command path is used in-process. + ValidateSettings -settings $settings + } + else { + # On PS < 7, validation is skipped entirely; pwsh should never be called + Mock pwsh { throw "pwsh should not be called on PS < 7" } + + ValidateSettings -settings $settings + + # Verify pwsh was NOT called + Should -Invoke -CommandName pwsh -Times 0 + } + + # Verify no warning was output + Should -Invoke -CommandName OutputWarning -Times 0 + } } }