3
3
4
4
# Build script for MSTest Test Framework.
5
5
6
- [CmdletBinding (PositionalBinding = $false )]
6
+ [CmdletBinding (PositionalBinding = $false )]
7
7
Param (
8
8
[ValidateSet (" Debug" , " Release" )]
9
9
[Alias (" c" )]
18
18
[Alias (" vs" )]
19
19
[string ] $VersionSuffix = " dev" ,
20
20
21
- [string ] $BuildVersionPrefix = " 14.0" ,
21
+ [string ] $BuildVersionPrefix = " 14.0" ,
22
22
23
23
[string ] $BuildVersionSuffix = " 9999.99" ,
24
24
@@ -47,7 +47,13 @@ Param(
47
47
[Switch ] $IsLocalizedBuild ,
48
48
49
49
[Alias (" tpv" )]
50
- [string ] $TestPlatformVersion = $null
50
+ [string ] $TestPlatformVersion = $null ,
51
+
52
+ [Alias (" f" )]
53
+ [Switch ] $Force ,
54
+
55
+ [Alias (" s" )]
56
+ [String []] $Steps = @ (" UpdateTPVersion" , " Restore" , " Build" , " Publish" )
51
57
)
52
58
53
59
. $PSScriptRoot \common.lib.ps1
@@ -73,7 +79,7 @@ $TFB_Solutions = @(
73
79
" TestFx.sln"
74
80
)
75
81
76
- $TFB_NetCoreProjects = @ (
82
+ $TFB_NetCoreProjects = @ (
77
83
" src\Adapter\PlatformServices.NetCore\PlatformServices.NetCore.csproj"
78
84
79
85
" test\ComponentTests\TestAssets\TestProjectForAssemblyResolution\TestProjectForAssemblyResolution.csproj"
@@ -132,8 +138,7 @@ function Perform-Restore {
132
138
133
139
Write-Log " Perform-Restore: Started."
134
140
135
- if ($TFB_SkipRestore )
136
- {
141
+ if ($TFB_SkipRestore ) {
137
142
Write-Log " Perform-Restore: Skipped."
138
143
return ;
139
144
}
@@ -159,12 +164,11 @@ function Perform-Restore {
159
164
$msbuildPath = Locate- MSBuildPath
160
165
161
166
Write-Verbose " Starting solution restore..."
162
- foreach ($solution in $TFB_Solutions )
163
- {
164
- $solutionPath = Locate- Item - relativePath $solution
167
+ foreach ($solution in $TFB_Solutions ) {
168
+ $solutionPath = Locate- Item - relativePath $solution
165
169
166
- Write-Verbose " $nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath "
167
- & $nuget restore - msbuildPath $msbuildPath - verbosity quiet - nonInteractive - configFile $nugetConfig $solutionPath
170
+ Write-Verbose " $nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath "
171
+ & $nuget restore - msbuildPath $msbuildPath - verbosity quiet - nonInteractive - configFile $nugetConfig $solutionPath
168
172
}
169
173
170
174
if ($lastExitCode -ne 0 ) {
@@ -174,8 +178,7 @@ function Perform-Restore {
174
178
$msbuild = Join-Path $msbuildPath " MSBuild.exe"
175
179
176
180
Write-Verbose " Starting restore for NetCore Projects"
177
- foreach ($project in $TFB_NetCoreProjects )
178
- {
181
+ foreach ($project in $TFB_NetCoreProjects ) {
179
182
$projectPath = Locate- Item - relativePath $project
180
183
181
184
Write-Verbose " $msbuild /t:restore -verbosity:minimal $projectPath /m"
@@ -197,16 +200,13 @@ function Perform-Build {
197
200
198
201
Write-Log " Perform-Build: Started."
199
202
200
- if ($TFB_Clean )
201
- {
203
+ if ($TFB_Clean ) {
202
204
$foldersToDel = @ ( $TFB_Configuration , " TestAssets" )
203
205
Write-Log " Clean build requested."
204
- foreach ($folder in $foldersToDel )
205
- {
206
+ foreach ($folder in $foldersToDel ) {
206
207
$outDir = Join-Path $env: TF_OUT_DIR - ChildPath $folder
207
-
208
- if (Test-Path $outDir )
209
- {
208
+
209
+ if (Test-Path $outDir ) {
210
210
Write-Output " Deleting $outDir "
211
211
Remove-Item - Recurse - Force $outDir
212
212
}
@@ -218,87 +218,81 @@ function Perform-Build {
218
218
Write-Log " Perform-Build: Completed. {$ ( Get-ElapsedTime ($timer )) }"
219
219
}
220
220
221
- function Invoke-Build ([string ] $solution , $hasVsixExtension = " false" )
222
- {
221
+ function Invoke-Build ([string ] $solution , $hasVsixExtension = " false" ) {
223
222
$msbuild = Locate- MSBuild - hasVsixExtension $hasVsixExtension
224
- $solutionPath = Locate- Item - relativePath $solution
223
+ $solutionPath = Locate- Item - relativePath $solution
225
224
$solutionDir = [System.IO.Path ]::GetDirectoryName($solutionPath )
226
225
$solutionSummaryLog = Join-Path - path $solutionDir - childPath " msbuild.log"
227
226
$solutionWarningLog = Join-Path - path $solutionDir - childPath " msbuild.wrn"
228
227
$solutionFailureLog = Join-Path - path $solutionDir - childPath " msbuild.err"
229
228
230
- Write-Log " Building $solution ..."
231
- Write-Verbose " $msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m"
232
- & $msbuild / t:$Target / p:Configuration= $configuration / v:m / flp1:Summary` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionSummaryLog / flp2:WarningsOnly` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionWarningLog / flp3:ErrorsOnly` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionFailureLog / p:IsLocalizedBuild= $TFB_IsLocalizedBuild / p:UpdateXlf= $TFB_UpdateXlf / p:BuildVersion= $TFB_BuildVersion $solutionPath / bl / m
229
+ Write-Log " Building $solution ..."
230
+ Write-Verbose " $msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m"
231
+ & $msbuild / t:$Target / p:Configuration= $configuration / v:m / flp1:Summary` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionSummaryLog / flp2:WarningsOnly` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionWarningLog / flp3:ErrorsOnly` ;Verbosity= diagnostic` ;Encoding= UTF- 8 ` ;LogFile= $solutionFailureLog / p:IsLocalizedBuild= $TFB_IsLocalizedBuild / p:UpdateXlf= $TFB_UpdateXlf / p:BuildVersion= $TFB_BuildVersion $solutionPath / bl / m
233
232
234
- if ($lastExitCode -ne 0 ) {
235
- throw " Build failed with an exit code of '$lastExitCode '."
236
- }
233
+ if ($lastExitCode -ne 0 ) {
234
+ throw " Build failed with an exit code of '$lastExitCode '."
235
+ }
237
236
}
238
237
239
238
#
240
239
# Creates Fx & Adapter nuget packages
241
240
#
242
- function Create-NugetPackages
243
- {
244
- $timer = Start-Timer
241
+ function Create-NugetPackages {
242
+ $timer = Start-Timer
245
243
246
- Write-Log " Create-NugetPackages: Started."
244
+ Write-Log " Create-NugetPackages: Started."
247
245
248
- $stagingDir = Join-Path $env: TF_OUT_DIR $TFB_Configuration
249
- $packageOutDir = Join-Path $stagingDir " MSTestPackages"
250
- $tfSrcPackageDir = Join-Path $env: TF_SRC_DIR " Package"
246
+ $stagingDir = Join-Path $env: TF_OUT_DIR $TFB_Configuration
247
+ $packageOutDir = Join-Path $stagingDir " MSTestPackages"
248
+ $tfSrcPackageDir = Join-Path $env: TF_SRC_DIR " Package"
251
249
252
- # Copy over the nuspecs to the staging directory
253
- if ($TFB_Official )
254
- {
255
- $nuspecFiles = @ (" MSTest.TestAdapter.Dotnet.nuspec" , " MSTest.TestAdapter.nuspec" , " MSTest.TestAdapter.symbols.nuspec" , " MSTest.TestFramework.nuspec" , " MSTest.TestFramework.symbols.nuspec" , " MSTest.Internal.TestFx.Documentation.nuspec" )
256
- }
257
- else
258
- {
259
- $nuspecFiles = @ (" MSTest.TestAdapter.Enu.nuspec" , " MSTest.TestFramework.enu.nuspec" , " MSTest.TestAdapter.Dotnet.nuspec" )
260
- }
250
+ # Copy over the nuspecs to the staging directory
251
+ if ($TFB_Official ) {
252
+ $nuspecFiles = @ (" MSTest.TestAdapter.Dotnet.nuspec" , " MSTest.TestAdapter.nuspec" , " MSTest.TestAdapter.symbols.nuspec" , " MSTest.TestFramework.nuspec" , " MSTest.TestFramework.symbols.nuspec" , " MSTest.Internal.TestFx.Documentation.nuspec" )
253
+ }
254
+ else {
255
+ $nuspecFiles = @ (" MSTest.TestAdapter.Enu.nuspec" , " MSTest.TestFramework.enu.nuspec" , " MSTest.TestAdapter.Dotnet.nuspec" )
256
+ }
261
257
262
- foreach ($file in $nuspecFiles ) {
263
- Copy-Item $tfSrcPackageDir \$file $stagingDir - Force
264
- }
258
+ foreach ($file in $nuspecFiles ) {
259
+ Copy-Item $tfSrcPackageDir \$file $stagingDir - Force
260
+ }
265
261
266
- # Copy over LICENSE.txt file to staging directory
267
- $licenseFilePath = Join-Path $env: TF_ROOT_DIR " LICENSE.txt"
268
- Copy-Item $licenseFilePath $stagingDir - Force
262
+ # Copy over LICENSE.txt file to staging directory
263
+ $licenseFilePath = Join-Path $env: TF_ROOT_DIR " LICENSE.txt"
264
+ Copy-Item $licenseFilePath $stagingDir - Force
269
265
270
- # Call nuget pack on these components.
271
- $nugetExe = Locate- Nuget
266
+ # Call nuget pack on these components.
267
+ $nugetExe = Locate- Nuget
272
268
273
- foreach ($file in $nuspecFiles ) {
274
- $version = $TFB_FrameworkVersion
269
+ foreach ($file in $nuspecFiles ) {
270
+ $version = $TFB_FrameworkVersion
275
271
276
- if ($file.Contains (" TestAdapter" ))
277
- {
278
- $version = $TFB_AdapterVersion
279
- }
280
-
281
- if (! [string ]::IsNullOrEmpty($TFB_VersionSuffix ))
282
- {
283
- $versionSuffix = $TFB_VersionSuffix -replace " \." , " -"
284
- $version = $version + " -" + $versionSuffix
285
- }
286
-
287
- Write-Verbose " $nugetExe pack $stagingDir \$file -OutputDirectory $packageOutDir -Version=$version -Properties Version=$version "
288
- & $nugetExe pack $stagingDir \$file - OutputDirectory $packageOutDir - Version $version - Properties Version= $version ` ;Srcroot= $env: TF_SRC_DIR ` ;Packagesroot= $env: TF_PACKAGES_DIR
289
-
290
- if ($lastExitCode -ne 0 ) {
291
- throw " Nuget pack failed with an exit code of '$lastExitCode '."
292
- }
272
+ if ($file.Contains (" TestAdapter" )) {
273
+ $version = $TFB_AdapterVersion
274
+ }
275
+
276
+ if (! [string ]::IsNullOrEmpty($TFB_VersionSuffix )) {
277
+ $versionSuffix = $TFB_VersionSuffix -replace " \." , " -"
278
+ $version = $version + " -" + $versionSuffix
279
+ }
280
+
281
+ Write-Verbose " $nugetExe pack $stagingDir \$file -OutputDirectory $packageOutDir -Version=$version -Properties Version=$version "
282
+ & $nugetExe pack $stagingDir \$file - OutputDirectory $packageOutDir - Version $version - Properties Version= $version ` ;Srcroot= $env: TF_SRC_DIR ` ;Packagesroot= $env: TF_PACKAGES_DIR
283
+
284
+ if ($lastExitCode -ne 0 ) {
285
+ throw " Nuget pack failed with an exit code of '$lastExitCode '."
293
286
}
287
+ }
294
288
295
- Write-Log " Create-NugetPackages: Complete. {$ ( Get-ElapsedTime ($timer )) }"
289
+ Write-Log " Create-NugetPackages: Complete. {$ ( Get-ElapsedTime ($timer )) }"
296
290
}
297
291
298
292
function Replace-InFile ($File , $RegEx , $ReplaceWith ) {
299
293
$content = Get-Content - Raw - Encoding utf8 $File
300
- $newContent = ($content -replace $RegEx , $ReplaceWith )
301
- if (-not $content.Equals ($newContent )) {
294
+ $newContent = ($content -replace $RegEx , $ReplaceWith )
295
+ if (-not $content.Equals ($newContent )) {
302
296
Write-Log " Updating TestPlatform version in $File "
303
297
$newContent | Set-Content - Encoding utf8 $File - NoNewline
304
298
}
@@ -313,19 +307,46 @@ function Sync-PackageVersions {
313
307
314
308
if ([String ]::IsNullOrWhiteSpace($TestPlatformVersion )) {
315
309
$TestPlatformVersion = (([XML ](Get-Content $versionsFile )).Project.PropertyGroup.TestPlatformVersion).InnerText
316
- } else {
310
+ }
311
+ else {
317
312
Replace- InFile - File $versionsFile - RegEx $versionsRegex - ReplaceWith " <`$ 1>$TestPlatformVersion </TestPlatformVersion>"
318
313
}
319
314
320
- (Get-ChildItem " $PSScriptRoot \..\src\*packages.config" , " $PSScriptRoot \..\test\*packages.config" - Recurse) | ForEach-Object {
315
+ (Get-ChildItem " $PSScriptRoot \..\src\*packages.config" , " $PSScriptRoot \..\test\*packages.config" - Recurse) | ForEach-Object {
321
316
Replace- InFile - File $_ - RegEx $packageRegex - ReplaceWith (' <package id="Microsoft.TestPlatform$1" version="{0}"' -f $TestPlatformVersion )
322
317
}
323
318
324
319
Replace- InFile - File " $PSScriptRoot \..\test\E2ETests\Automation.CLI\CLITestBase.cs" - RegEx $sourceRegex - ReplaceWith (' $1Microsoft.TestPlatform.{0}";' -f $TestPlatformVersion )
325
320
}
326
321
322
+ function ShouldRunStep ([string []]$CurrentSteps ) {
323
+ if ($Force ) {
324
+ return $true
325
+ }
326
+
327
+ foreach ($step in $CurrentSteps ) {
328
+ if ($Steps -contains $step ) {
329
+ return $true
330
+ }
331
+ }
332
+
333
+ return $false
334
+ }
335
+
327
336
Print- Help
328
- Sync-PackageVersions
329
- Perform- Restore
330
- Perform- Build
331
- Create- NugetPackages
337
+
338
+ if (ShouldRunStep @ (" UpdateTPVersion" )) {
339
+ Sync-PackageVersions
340
+ }
341
+
342
+ if (ShouldRunStep @ (" UpdateTPVersion" , " Restore" )) {
343
+ Perform- Restore
344
+ }
345
+
346
+ if (ShouldRunStep @ (" Build" )) {
347
+ Perform- Build
348
+ }
349
+
350
+ if (ShouldRunStep @ (" Publish" )) {
351
+ Create- NugetPackages
352
+ }
0 commit comments