|
| 1 | +param |
| 2 | +( |
| 3 | + [Switch]$Archive, |
| 4 | + [String]$BlockedSolutions, |
| 5 | + [String]$Configuration = "Release", |
| 6 | + [Switch]$Clean, |
| 7 | + [Switch]$Help |
| 8 | +) |
| 9 | + |
| 10 | +$work = $pwd |
| 11 | +$blockedSolutionsList = $BlockedSolutions.Split(";"); |
| 12 | +$artifactsDir = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($work, "Artifacts")) |
| 13 | + |
| 14 | +if ($Help) |
| 15 | +{ |
| 16 | + Write-Host "Code Mods Build Script" |
| 17 | + Write-Host |
| 18 | + Write-Host "Parameters:" |
| 19 | + Write-Host "-Archive - archives the build artifacts." |
| 20 | + Write-Host "-BlockedSolutions - semi-colon separated list of solutions not to build." |
| 21 | + Write-Host "-Configuration [name] - build with a specific configuration." |
| 22 | + Write-Host "-Clean - clean the solutions before building." |
| 23 | + Write-Host "-Help - display help." |
| 24 | + exit |
| 25 | +} |
| 26 | + |
| 27 | +$vs = ./Tools/vswhere.exe -nologo -latest -prerelease -property installationPath |
| 28 | +$vsCommonTools = [System.IO.Path]::Combine($vs, "Common7", "Tools") |
| 29 | + |
| 30 | +pushd $vsCommonTools |
| 31 | + cmd /c "VsDevCmd.bat > nul 2> nul &set" | |
| 32 | + foreach { |
| 33 | + if ($_ -match "=") { |
| 34 | + $v = $_.split("=", 2) |
| 35 | + Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])" |
| 36 | + } |
| 37 | + } |
| 38 | +popd |
| 39 | + |
| 40 | +function GetProjectProperty([String]$in_projectPath, [String]$in_propertyName) |
| 41 | +{ |
| 42 | + return & msbuild /NoLogo /p:Configuration="${Configuration}" -getProperty:"${in_propertyName}" "${in_projectPath}" |
| 43 | +} |
| 44 | + |
| 45 | +foreach ($solutionPath in [System.IO.Directory]::EnumerateFiles("${work}/Games/", "*.sln", [System.IO.SearchOption]::AllDirectories)) |
| 46 | +{ |
| 47 | + $solutionDir = Split-Path $solutionPath |
| 48 | + $solutionName = [System.IO.Path]::GetFileNameWithoutExtension($solutionPath) |
| 49 | + |
| 50 | + if ($blockedSolutionsList.Contains($solutionName)) |
| 51 | + { |
| 52 | + continue |
| 53 | + } |
| 54 | + |
| 55 | + $target = "Build" |
| 56 | + |
| 57 | + if ($Clean) |
| 58 | + { |
| 59 | + $target = "Clean;" + $target |
| 60 | + } |
| 61 | + |
| 62 | + Write-Host |
| 63 | + Write-Host ("**************" + '*' * $solutionPath.Length) -ForegroundColor DarkGreen |
| 64 | + Write-Host "* Solution: ${solutionPath} *" -ForegroundColor DarkGreen |
| 65 | + Write-Host ("**************" + '*' * $solutionPath.Length) -ForegroundColor DarkGreen |
| 66 | + |
| 67 | + & msbuild /NoLogo /v:m /t:"${target}" /Restore /p:RestorePackagesConfig=true /p:Configuration="${Configuration}" "${solutionPath}" |
| 68 | + |
| 69 | + if ($Archive) |
| 70 | + { |
| 71 | + $projects = dotnet sln "${solutionPath}" list | |
| 72 | + Select-Object -Skip 2 | |
| 73 | + ForEach-Object { |
| 74 | + Join-Path $solutionDir $_.Trim() |
| 75 | + } |
| 76 | + |
| 77 | + foreach ($project in $projects) |
| 78 | + { |
| 79 | + $projectDir = GetProjectProperty $project "ProjectDir" |
| 80 | + $projectName = GetProjectProperty $project "ProjectName" |
| 81 | + $binDir = [System.IO.Path]::Combine($projectDir, "bin") |
| 82 | + |
| 83 | + if (![System.IO.Directory]::Exists($binDir)) |
| 84 | + { |
| 85 | + Write-Host |
| 86 | + Write-Host ("***********************" + '*' * $binDir.Length) -ForegroundColor DarkRed |
| 87 | + Write-Host "* Cannot archive project binaries." -ForegroundColor DarkRed |
| 88 | + Write-Host "* Directory not found: ${binDir}" -ForegroundColor DarkRed |
| 89 | + Write-Host ("***********************" + '*' * $binDir.Length) -ForegroundColor DarkRed |
| 90 | + |
| 91 | + exit -1 |
| 92 | + } |
| 93 | + |
| 94 | + $solutionArtifactsDir = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($artifactsDir.FullName, $solutionName)) |
| 95 | + $projectArtifactPath = [System.IO.Path]::Combine($solutionArtifactsDir.FullName, "${projectName}.zip") |
| 96 | + |
| 97 | + cd $binDir |
| 98 | + Compress-Archive -Force * $projectArtifactPath |
| 99 | + cd $work |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments