/ .pipelines / verifyPossibleAssetConflicts.ps1
verifyPossibleAssetConflicts.ps1
 1  [CmdletBinding()]
 2  Param(
 3      [Parameter(Mandatory = $True, Position = 1)]
 4      [string]$targetDir
 5  )
 6  
 7  # This script runs some simple checks to avoid conflicts between assets from different applications during build time.
 8  $totalFailures = 0
 9  
10  # Verify if the Assets folder contains only sub-folders.
11  # The purpose is to avoid applications having assets files that might conflict with other applications.
12  # Applications should be setting their own directory for assets.
13  
14  $targetAssetsDir = $targetDir + "/Assets"
15  
16  $nonDirectoryAssetsItems = Get-ChildItem $targetAssetsDir -Attributes !Directory
17  $directoryAssetsItems = Get-ChildItem $targetAssetsDir -Attributes Directory
18  
19  if ($directoryAssetsItems.Count -le 0) {
20      Write-Host -ForegroundColor Red "No directories detected in " $nonDirectoryAssetsItems ". Are you sure this is the right path?`r`n"
21      $totalFailures++;
22  } elseif ($nonDirectoryAssetsItems.Count -gt 0) {
23      Write-Host -ForegroundColor Red "Detected " $nonDirectoryAssetsItems " files in " $targetAssetsDir "`r`n"
24      $totalFailures++;
25  } else {
26      Write-Host -ForegroundColor Green "Only directories detected in " $targetAssetsDir "`r`n"
27  }
28  
29  # Make sure there's no resources.pri file. Each application should use a different name for their own resources file path.
30  $resourcesPriFiles = Get-ChildItem $targetDir -Filter resources.pri
31  if ($resourcesPriFiles.Count -gt 0) {
32      Write-Host -ForegroundColor Red "Detected a resources.pri file in " $targetDir "`r`n"
33      $totalFailures++;
34  } else {
35      Write-Host -ForegroundColor Green "No resources.pri file detected in " $targetDir "`r`n"
36  }
37  
38  # Each application should have their XAML files in their own paths to avoid these conflicts.
39  $resourcesPriFiles = Get-ChildItem $targetDir -Filter *.xbf
40  if ($resourcesPriFiles.Count -gt 0) {
41      Write-Host -ForegroundColor Red "Detected a .xbf file in " $targetDir "`r`n"
42      $totalFailures++;
43  } else {
44      Write-Host -ForegroundColor Green "No .xbf files detected in " $targetDir "`r`n"
45  }
46  
47  if ($totalFailures -gt 0) {
48      Write-Host -ForegroundColor Red "Found some errors when verifying " $targetDir "`r`n"
49      exit 1
50  }
51  
52  exit 0