Created
November 16, 2020 10:47
-
-
Save Fazzani/d21ce89f736566f8f5624f26bf59e299 to your computer and use it in GitHub Desktop.
Revisions
-
Fazzani created this gist
Nov 16, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ # Project Guid Generator # Creator: Unknown # Editor: Isaac martinez # Notes: A requirement of SonarCloud/SonarQube is that all projects have a unique # ProjectGuid. This script takes care of that. This script will recursively # look for projects in subfolders and apply the necessary changes. # Version Date: 05/19/2020 $paths = Get-ChildItem -Path $PSScriptRoot -include *proj -Recurse Write-Host $paths.count "project(s) found" $projectGuids = @() foreach ($pathobject in $paths) { $path = $pathobject.fullname $doc = New-Object System.Xml.XmlDocument $doc.Load($path) $node = $doc.SelectSingleNode("//Project/PropertyGroup/ProjectGuid") if (!$node) { $child = $doc.CreateElement("ProjectGuid") $child.InnerText = [guid]::NewGuid().ToString().ToUpper() $node = $doc.SelectSingleNode("//Project/PropertyGroup") if (!$node){ Write-Host "Error:" $path "- Project file is missing //Project/PropertyGroup node" } else { $node.AppendChild($child) $doc.Save($path) $projectGuids += $child.InnerText.ToUpper() } } elseif($projectGuids.Contains($node.InnerText)){ Write-Host "Duplicate found" $node.InnerText = [guid]::NewGuid().ToString().ToUpper() $doc.Save($path) $projectGuids += $node.InnerText.ToUpper(); } else{ $projectGuids += $node.InnerText; Write-Host $path "already has a valid ProjectGuid" } }