Visual Studio Online build step task snippets

Visual Studio Online build definitions & tasks have certainly come a long way since the old xaml template days. There is even a VSO extensions market place. For my current project we are using good old PowerShell based tasks which work together to continuously deploy the solution from VSO to a single node Azure VM Service Fabric cluster which runs all unit, integration and automated UI tests. Some PowerShell snippets which I’ve found helpful along the way are detailed below.

The following task snippet is used to check that a Service Fabric hosted Web endpoint is reachable and ready for integration and UI testing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$statuscode = 0
while($statuscode -ne 200)
{
try
{
$statuscode = (Invoke-WebRequest -Uri "http://localhost").statuscode
}
catch
{
Write-Host "$(Get-Date) ....http://localhost is unreachable, sleeping for 30sec"
Start-Sleep -s 30
}
}
Write-Host "$(Get-Date) ....http://localhost is now reachable, continuing"

Logs the content of a test settings xml file and filters out any keys containing the string “Secret”:

1
2
[xml]$testSettings = Get-Content -Path $args[0]
$testSettings.configuration.appSettings.add | Where-Object {$_.key -notmatch "Secret"}

For xUnit tests the provided Visual Studio Test step can be configured with multiple target assemblies separated by a “;” character and wherever possible enable Run In Parallel. Also note to be careful not to end the line with a “;” character as VSO will think there is a missing assembly! For example:

Execution Options >> Test Assembly

$(Build.SourcesDirectory)\test\AcmeCore.Test\bin\$(BuildConfiguration)\AcmeCore.Test.dll;
$(Build.SourcesDirectory)\test\AcmeCommon.Test\bin\$(BuildConfiguration)\AcmeCommon.Test.dll

Advanced Execution Options >> Path to Custom Test Adapters

$(Build.SourcesDirectory)\packages\xunit.runner.visualstudio.2.2.0-beta1-build1144\build\_common\xunit.runner.visualstudio.testadapter.dll