$header = @" "@ $footer = @" "@ function WriteBuilds($allConfigs, $srcDir, $projName) { $configs = ""; # Sort via Target then OS $ac = $allConfigs | sort target, os foreach($c in $ac) { if ($c.relpath -eq $null) { continue } $config = " $dc"; $projectLines = $pf[0..1]; $pfContinue = 2; if ($pf[2] -match "Import") { $projectLines += " "; $projectLines += $projectConfigProperty; $projectLines += " " } else { if ($pf[3] -match "Configuration") { $pf[3] = $projectConfigProperty; } elseif ($pf[3] -match "Setting default TargetGroup" -and $pf[4] -match "TargetGroup") { $projectLines += " "; $projectLines += $projectConfigProperty; $projectLines += " " $pfContinue = 6; } else { Write-Host $($proj.FullName + " doesn't have a Configuration block!"); s $proj.FullName } } $projectLines += $pf[$pfContinue..$pf.Length]; sc $proj.FullName $projectLines } } function CleanupProjects($proj, $pf) { $writeFile = $false; $lineCount $filtered += $pf | ? { $lineCount++; if ($lineCount -gt 4 -and $_ -match "Library") { $writeFile = $true; return $false; } return $true; }; if ($writeFile) { sc $proj.FullName $filtered } } function GetConfigurations($projs, $srcDir, $projName) { $allConfigs = @(); foreach($proj in $projs) { $pf = gc $proj; $pfcs = @(); #CleanupProjects $proj $pf $pf | ? { $_ -match "'(?Windows|Linux|OSX|FreeBSD)?_?(?net\d\d\d?|netcore\d\d|netcore\d\daot|netcoreapp\d\.\d|dnxcore\d\d|dotnet\d\d)?_?Debug\|AnyCPU'" } | % { $os = $matches["osg"]; $target = $matches["tg"]; $relPath = $proj.FullName.Replace($srcDir.FullName+"\", ""); #if ($target -match "netcore.+") { $os = "Windows" } if ($os -eq "Windows") { $os = "Windows_NT" } $ht = new-object System.Object $ht | Add-Member -type NoteProperty -name os -value $os $ht | Add-Member -type NoteProperty -name target -value $target $ht | Add-Member -type NoteProperty -name relPath -value $relPath $ht | Add-Member -type NoteProperty -name projName -value $projName $ht | Add-Member -type NoteProperty -name sortKey -value $($os+"-"+$target+"_"+$relPath) $pfcs += $ht; } $defaultConfig = GetDefaultConfiguration $pfcs $proj.FullName WriteDefaultConfiguration $defaultConfig $proj $pf $allConfigs += $pfcs; } return $allConfigs | sort target, os; } $srcDirs = dir .\src\*\src foreach($srcDir in $srcDirs) { #$srcDir.FullName $projs = dir $srcDir -r -i *.*proj if($projs.Count -eq 0) { Write-Host "Skipping $srcDir because it has no csproj files."; continue; } $projName = $srcDir.Parent.Name; $allSrcConfigs = GetConfigurations $projs $srcDir $projName $defaultConfig = GetDefaultConfiguration $allSrcConfigs $projName $testsDir = $srcDir.Parent.FullName + "\tests"; if (Test-Path $testsDir) { $testProjs = dir $testsDir -r -i *.csproj if ($defaultConfig.os -eq "Windows_NT") { #$testProjs | % { WriteDefaultConfiguration $defaultConfig $_ $(gc $_) } } } #$testConfigs = GetConfigurations $testProjs $testsDir $projName WriteBuilds $allSrcConfigs $srcDir $projName $bfs = dir $srcDir -r -i *.builds if ($bfs.Count -ne 1) { $projName + " contains " + $bfs.Count + " builds files!"; } }