From 813f76138cd2356b515eab2ae6e5e08138809b3c Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Fri, 24 Apr 2026 17:25:50 -0400 Subject: [PATCH] Fix web.config patch: use XPath instead of property navigation Property-path navigation returns an empty string when the wrapper is absent from the published web.config, causing AppendChild to fail. SelectSingleNode("//aspNetCore") works regardless of structure. Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile.dev | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile.dev b/Jenkinsfile.dev index 46b063a..21cc35b 100644 --- a/Jenkinsfile.dev +++ b/Jenkinsfile.dev @@ -68,24 +68,30 @@ pipeline { powershell ''' $path = "C:\\inetpub\\wwwroot\\web.config" $xml = [xml](Get-Content $path) - $aspNetCore = $xml.configuration.location.'system.webServer'.aspNetCore + + # Use XPath so the structure (with or without wrapper) doesn't matter + $aspNetCore = $xml.SelectSingleNode("//aspNetCore") + if ($null -eq $aspNetCore) { + Write-Error "Could not find aspNetCore element in web.config" + exit 1 + } # Ensure environmentVariables element exists - if (-not $aspNetCore.environmentVariables) { + $envVarsNode = $aspNetCore.SelectSingleNode("environmentVariables") + if ($null -eq $envVarsNode) { $envVarsNode = $xml.CreateElement("environmentVariables") $aspNetCore.AppendChild($envVarsNode) | Out-Null } # Remove existing ASPNETCORE_ENVIRONMENT entry if present - $existing = $aspNetCore.environmentVariables.environmentVariable | - Where-Object { $_.name -eq "ASPNETCORE_ENVIRONMENT" } - if ($existing) { $aspNetCore.environmentVariables.RemoveChild($existing) | Out-Null } + $existing = $envVarsNode.SelectSingleNode("environmentVariable[@name='ASPNETCORE_ENVIRONMENT']") + if ($existing) { $envVarsNode.RemoveChild($existing) | Out-Null } # Add fresh entry $envVar = $xml.CreateElement("environmentVariable") $envVar.SetAttribute("name", "ASPNETCORE_ENVIRONMENT") $envVar.SetAttribute("value", "Development") - $aspNetCore.environmentVariables.AppendChild($envVar) | Out-Null + $envVarsNode.AppendChild($envVar) | Out-Null $xml.Save($path) Write-Host "web.config patched: ASPNETCORE_ENVIRONMENT=Development"