|
| 1 | +param ( |
| 2 | + [switch]$Debug, |
| 3 | + [string]$VisualStudioVersion = '14.0', |
| 4 | + [switch]$SkipKeyCheck, |
| 5 | + [string]$Verbosity = 'normal', |
| 6 | + [string]$Logger |
| 7 | +) |
| 8 | + |
| 9 | +# build the solution |
| 10 | +$SolutionPath = "..\AsyncUsageAnalyzers.sln" |
| 11 | + |
| 12 | +# make sure the script was run from the expected path |
| 13 | +if (!(Test-Path $SolutionPath)) { |
| 14 | + $host.ui.WriteErrorLine('The script was run from an invalid working directory.') |
| 15 | + exit 1 |
| 16 | +} |
| 17 | + |
| 18 | +. .\version.ps1 |
| 19 | + |
| 20 | +If ($Debug) { |
| 21 | + $BuildConfig = 'Debug' |
| 22 | +} Else { |
| 23 | + $BuildConfig = 'Release' |
| 24 | +} |
| 25 | + |
| 26 | +If ($Version.Contains('-')) { |
| 27 | + $KeyConfiguration = 'Dev' |
| 28 | +} Else { |
| 29 | + $KeyConfiguration = 'Final' |
| 30 | +} |
| 31 | + |
| 32 | +# download NuGet.exe if necessary |
| 33 | +$nuget = '..\.nuget\NuGet.exe' |
| 34 | +If (-not (Test-Path $nuget)) { |
| 35 | + If (-not (Test-Path '..\.nuget')) { |
| 36 | + mkdir '..\.nuget' |
| 37 | + } |
| 38 | + |
| 39 | + $nugetSource = 'http://nuget.org/nuget.exe' |
| 40 | + Invoke-WebRequest $nugetSource -OutFile $nuget |
| 41 | + If (-not $?) { |
| 42 | + $host.ui.WriteErrorLine('Unable to download NuGet executable, aborting!') |
| 43 | + exit $LASTEXITCODE |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +# build the main project |
| 48 | +$msbuild = "${env:ProgramFiles(x86)}\MSBuild\$VisualStudioVersion\Bin\MSBuild.exe" |
| 49 | + |
| 50 | +# Attempt to restore packages up to 3 times, to improve resiliency to connection timeouts and access denied errors. |
| 51 | +$maxAttempts = 3 |
| 52 | +For ($attempt = 0; $attempt -lt $maxAttempts; $attempt++) { |
| 53 | + &$nuget 'restore' $SolutionPath |
| 54 | + If ($?) { |
| 55 | + Break |
| 56 | + } ElseIf (($attempt + 1) -eq $maxAttempts) { |
| 57 | + $host.ui.WriteErrorLine('Failed to restore required NuGet packages, aborting!') |
| 58 | + exit $LASTEXITCODE |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +If ($Logger) { |
| 63 | + $LoggerArgument = "/logger:$Logger" |
| 64 | +} |
| 65 | + |
| 66 | +&$msbuild '/nologo' '/m' '/nr:false' '/t:rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath |
| 67 | +If (-not $?) { |
| 68 | + $host.ui.WriteErrorLine('Build failed, aborting!') |
| 69 | + exit $LASTEXITCODE |
| 70 | +} |
| 71 | + |
| 72 | +# By default, do not create a NuGet package unless the expected strong name key files were used |
| 73 | +if (-not $SkipKeyCheck) { |
| 74 | + . .\keys.ps1 |
| 75 | + |
| 76 | + foreach ($pair in $Keys.GetEnumerator()) { |
| 77 | + $assembly = Resolve-FullPath -Path "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.dll" |
| 78 | + # Run the actual check in a separate process or the current process will keep the assembly file locked |
| 79 | + powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'" |
| 80 | + If (-not $?) { |
| 81 | + $host.ui.WriteErrorLine('Failed to verify strong name key for build, aborting!') |
| 82 | + exit $LASTEXITCODE |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +if (-not (Test-Path 'nuget')) { |
| 88 | + mkdir "nuget" |
| 89 | +} |
| 90 | + |
| 91 | +Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.nupkg" 'nuget' |
| 92 | +Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.symbols.nupkg" 'nuget' |
0 commit comments