Created
March 25, 2023 19:42
-
-
Save akanieski/06bdf33e3fa095e5491f5af6ef8c06bc to your computer and use it in GitHub Desktop.
Adjust SQL Project Files to enforce a given SqlCodeAnalysisRules set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
- name: rules | |
type: string | |
- name: directory | |
type: string | |
steps: | |
- powershell: | | |
$rules = '${{ parameters.rules }}' | |
$dir = '${{ parameters.directory }}' | |
$extension = "*.sqlproj" | |
$projFiles = Get-ChildItem -Path $dir -Recurse -Include $extension | Select-Object -ExpandProperty FullName | ForEach-Object { | |
$content = Get-Content $_ | |
$regex = "(?<=<SqlCodeAnalysisRules>).*?(?=<\/SqlCodeAnalysisRules>)" | |
if (-not ($content -match "SqlCodeAnalysisRules")) { | |
Write-Host "No SQL Rules found in $_ .. Adding them" | |
$newContent = $content -replace "</Project>", " <PropertyGroup>`r`n <SqlCodeAnalysisRules>$rules</SqlCodeAnalysisRules>`r`n </PropertyGroup>`r`r</Project>" | |
} else { | |
Write-Host "Swapping out existing rules in $_ " | |
$newContent = $content -replace $regex, $rules | |
} | |
Set-Content $_ -Value $newContent | |
} | |
displayName: Adjust SQL Project Ruleset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment