$sldomain="mycompany.sealights.co"
$slagenttoken="$(AgentToken.Sandbox)"
$APP_NAME="MyApplication"
$APP_NAMESPACE="CalculatorServer.Controllers"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Output "Download the Sealights DotNet agent version set in settings..."
$agentversion = ((iwr -Uri https://$($sldomain)/api/v2/agents/dotnet/recommended -Headers @{'Accept' = 'application/json'; 'Authorization' = "Bearer $($slagenttoken)"}).Content `
| ConvertFrom-Json | Select-Object agent).agent.version
iwr -OutFile sealights-dotnet-agent.zip -Uri http://agents.sealights.co/SL.DotNet/SL.DotNet-$($agentversion).zip
Expand-Archive .\sealights-dotnet-agent.zip -DestinationPath SL.DotNet -Force
Write-Output "Sealights agent version used is: $(Get-Content .\SL.DotNet\version.txt)"
#Retrieve the same name of target branch as reported in Sealights Dashboard by removing the uncecessary prefix
$PR_TARGET_BRANCH="$(System.PullRequest.TargetBranch)".Replace("refs/heads/","")
#Retrieve the last Commit Hash from the PR branch and not the one from the ADO local Merge (via git log history)
$PR_LAST_COMMIT=$(git log -2 --format=%H).Split(" ")[1]
$PR_NUMBER="$(System.PullRequest.PullRequestId)"
$REPO_URL="$(System.PullRequest.SourceRepositoryURI)"
Write-Output "`n*** Create PR BSID ***"
.\SL.DotNet\x64\SL.DotNet.exe prConfig --appName $APP_NAME --pullRequestNumber $PR_NUMBER --targetBranch $PR_TARGET_BRANCH --latestCommit $PR_LAST_COMMIT --repositoryUrl $REPO_URL `
--includeNamespace $APP_NAMESPACE --buildSessionIdFile $(Build.ArtifactStagingDirectory)\SealightsBuildSessionId.txt --token $($slagenttoken) --logEnabled true --logAppendConsole true --ignoreCertificateErrors true
# Base path where all relative paths should start from. By default the agent searches for the solution file and uses its path for this value
$SOLUTION_DIR="$(Build.Repository.LocalPath)\src"
#Path to the source workspace
$SOURCE_DIR="$(Build.Repository.LocalPath)\src"
Write-Output "`n*** Prepare for MSBuild ***"
.\SL.DotNet\x64\SL.DotNet.exe prepareForMsBuild --buildSessionIdFile $(Build.ArtifactStagingDirectory)\SealightsBuildSessionId.txt --workspacePath $SOLUTION$SOURCE_DIR `
--baseDir $SOURCE$SOLUTION_DIR --ignoreGeneratedCode true --debugMode true --logEnabled true --logAppendConsole true --ignoreCertificateErrors true --token $($slagenttoken) --scm git --scmProvider vsts |