Skip to content

Commit e1710ce

Browse files
author
Nitin Gurram
authored
Fix Windows 7 DTA Issue with Certificate import (#4720)
* bug fixes for windows7 support on DTA V2. * updating the task version as well. * review comments + bug fixes + min version of powershell * review comment.
1 parent 7635cd4 commit e1710ce

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function ExtractAgentArchive ($SetupArchive, $Destination) {
1+
function ExtractAgentArchive ($SetupArchive, $Destination) {
22
Write-Verbose "Extracting the archive $SetupArchive"
33
Try {
44
Add-Type -AssemblyName System.IO.Compression.FileSystem
@@ -25,9 +25,29 @@ function InstallTestAgent2017 {
2525
}
2626

2727
# First we need to install the certificates for TA 2017
28-
$SetupDir = Split-Path -Path $SetupPath
29-
Write-Verbose "Installing test agent certificates"
30-
Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
28+
$SetupDir = Split-Path -Path $SetupPath
29+
$certFiles = Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue
30+
if($certFiles -and $certFiles.Length -gt 0)
31+
{
32+
$osVersion = [environment]::OSVersion.Version
33+
Write-Verbose "Installing test agent certificates" -Verbose
34+
if ($osVersion.Major -eq "6" -and $osVersion.Minor -eq "1") {
35+
## Windows 7 SP1. Import-PfxCertificate is not present in windows 7
36+
Write-Verbose "Installing agent certificate(s) for Windows 7." -Verbose
37+
foreach($certFile in $certFiles)
38+
{
39+
Import-PfxCertificateWin7 -FilePath $certFile.FullName -CertRootStore "CurrentUser" -CertStore "My"
40+
}
41+
}
42+
else {
43+
Write-Verbose "Installing agent certificate(s) for Windows 8 or above." -Verbose
44+
$certFiles | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
45+
}
46+
Write-Verbose "Successfully installed the agent certificate." -Verbose
47+
}
48+
else {
49+
Write-Verbose "No test agent certificate found." -Verbose
50+
}
3151

3252
$p = New-Object System.Diagnostics.Process
3353
$Processinfo = New-Object System.Diagnostics.ProcessStartInfo
@@ -50,6 +70,22 @@ function InstallTestAgent2017 {
5070
return $p.ExitCode
5171
}
5272

73+
function Import-PfxCertificateWin7 {
74+
param
75+
(
76+
[Parameter (Mandatory=$true, ValueFromPipelineByPropertyName)]
77+
[String]$FilePath,
78+
[String]$CertRootStore="CurrentUser",
79+
[String]$CertStore="My"
80+
)
81+
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
82+
$pfx.import($FilePath, $pfxPass, "Exportable")
83+
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
84+
$store.open("MaxAllowed")
85+
$store.add($pfx)
86+
$store.close()
87+
}
88+
5389
function Install-Product($SetupPath, $ProductVersion, $Update) {
5490
$exitCode = 0
5591

Tasks/DeployVisualStudioTestAgent/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ To learn more about the general usage of the task, please see https://msdn.micro
66

77
### Prerequisites
88
The task requires:
9-
- .NET 4.6.1 on Windows8 or Windows 2K8R2
9+
- .NET 4.6.1 on Windows7 or Windows 2K8R2
10+
- PowerShell 3 or newer
1011
- Test machines should have PSRemoting enabled (run 'Enable-PSRemoting' on Windows Powershell)
1112
### WinRM setup
1213
This task uses the [Windows Remote Management](https://msdn.microsoft.com/en-us/library/aa384426.aspx) (WinRM) to access domain-joined or workgroup, on-premises physical or virtual machines.

Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,28 @@
171171

172172
$rootFolder = $ScheduleObject.GetFolder('\') #'
173173
$newTask = $rootFolder.RegisterTaskDefinition("DTA", $TaskDefinition, 6, '', '', 3)
174-
Write-Verbose "Starting scheduled task" -Verbose
175-
$rootFolder.DeleteTask("DTA", 0)
174+
Write-Verbose "Starting scheduled task on Windows 7." -Verbose
175+
Start-Sleep -Seconds 30
176+
$p = Get-Process -Name "DTAExecutionHost"
177+
$rootFolder.DeleteTask("DTA", 0)
176178
}
177179
else {
178180
# Windows 8 or above
179181
$action = New-ScheduledTaskAction -Execute "$SetupPath\DTAExecutionHost.exe" -Argument $dtaArgs
180182
$trigger = New-ScheduledTaskTrigger -AtLogOn
181-
$exePath = "$SetupPath\DTAExecutionHost.exe $dtaArgs"
182183

183184
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -OutVariable out -ErrorVariable err -ErrorAction SilentlyContinue | Out-Null
184185
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DTA" -Description "DTA UI" -RunLevel Highest -OutVariable out -ErrorVariable err | Out-Null
185186
Write-Verbose "Registering scheduled task output: $out error: $err" -Verbose
186187

187188
Start-ScheduledTask -TaskName "DTA" -OutVariable out -ErrorVariable err | Out-Null
188189
Write-Verbose "Starting scheduled task output: $out error: $err" -Verbose
190+
191+
Start-Sleep -Seconds 30
192+
$p = Get-Process -Name "DTAExecutionHost"
189193
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -ErrorAction SilentlyContinue
190194
}
191-
192-
Start-Sleep -Seconds 10
193195

194-
$p = Get-Process -Name "DTAExecutionHost" -ErrorAction SilentlyContinue
195196
if ($p) {
196197
return 0
197198
}

Tasks/DeployVisualStudioTestAgent/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 2,
1515
"Minor": 1,
16-
"Patch": 10
16+
"Patch": 11
1717
},
1818
"runsOn": [
1919
"Agent"

Tasks/DeployVisualStudioTestAgent/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 2,
1515
"Minor": 1,
16-
"Patch": 10
16+
"Patch": 11
1717
},
1818
"runsOn": [
1919
"Agent"

0 commit comments

Comments
 (0)