Skip to content

Commit c95a42b

Browse files
committed
Changes to improve environment setup for VS versions
1 parent 5472a8b commit c95a42b

File tree

3 files changed

+118
-44
lines changed

3 files changed

+118
-44
lines changed
Binary file not shown.
Binary file not shown.

EnvironmentSetup.ps1

Lines changed: 118 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,44 @@
33
Sets up a Node.js Tools for Visual Studio development environment from this branch.
44
55
.Parameter vstarget
6-
[Optional] The VS version to build for. If omitted, builds for all versions
7-
that are installed.
6+
[Optional] The VS version to build for. If omitted, checks for the Developer Tools environment variable.
87
98
Valid values: "14.0", "15.0"
109
1110
.Parameter vsroot
12-
[Optional] For VS15 only. Specifies the installation root directory of visual studio
11+
[Optional] For VS 2017 only. Specifies the installation root directory of visual studio
1312
1413
Example: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"
1514
16-
Must be specified when building for VS15.
15+
Must be specified when building for "15.0", unless running from the Developer Tools Command Prompt.
1716
17+
.Parameter microbuild
18+
[Optional] Installs the microbuild packages and exits (other operations are skipped).
19+
20+
.Parameter skipTestHost
21+
[Optional] Does not attempt to install the TestHost package if missing.
22+
23+
.Parameter skipRestore
24+
[Optional] Does not attempt to restore the nuget packages. (Default is to restore when targeting "15.0").
25+
1826
.Example
1927
.\EnvironmentSetup.ps1
2028
21-
Sets up NTVS development environmentironment for all compatible Visual Studio versions installed on machine
29+
Sets up NTVS development environment for the Visual Studio version matching the current Developer Tools prompt.
2230
2331
.Example
24-
.\EnvironmentSetup.ps1 -vstarget "15.0"
32+
.\EnvironmentSetup.ps1 -vstarget "14.0"
2533
26-
Sets up NTVS development environmentironment for specified Visual Studio versions installed on machine
34+
Sets up NTVS development environment for specified Visual Studio versions installed on machine
2735
#>
2836

2937
[CmdletBinding()]
3038
param(
3139
[string] $vstarget,
3240
[string] $vsroot,
3341
[switch] $microbuild,
34-
[switch] $skipTestHost
42+
[switch] $skipTestHost,
43+
[switch] $skipRestore
3544
)
3645

3746
If ((-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
@@ -42,56 +51,103 @@ If ((-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIden
4251
$rootDir = $PSScriptRoot
4352
Write-Output "Repository root: $($rootDir)"
4453

45-
46-
Import-Module -Force $rootDir\Build\VisualStudioHelpers.psm1
47-
$target_versions = get_target_vs_versions $vstarget $vsroot
48-
49-
Write-Output "Setting up NTVS development environment for $([String]::Join(", ", ($target_versions | % { $_.name })))"
50-
Write-Output "============================================================"
5154
$packagedir = if ($env:BUILD_BINARIESDIRECTORY) { "$env:BUILD_BINARIESDIRECTORY" } else { "$rootdir\packages" }
5255

56+
# Figure out which target to install for
57+
if (-not $vstarget) {
58+
if(-not $env:VisualStudioVersion) {
59+
Throw "Please either specify the -vstarget option, or run from a Developer Tools Command Prompt"
60+
} else {
61+
# If getting the VS version from the environment, get the install path there too for consistency
62+
$vstarget = $env:VisualStudioVersion
63+
}
64+
}
65+
5366
# Install microbuild packages
54-
if ($microbuild) {
67+
if ($microbuild -or ($vstarget -eq "15.0" -and -not $skipRestore)) {
5568
Write-Output ""
5669
Write-Output "Installing Nuget MicroBuild packages"
5770

5871
& "$rootdir\Nodejs\.nuget\nuget.exe" restore "$rootdir\Nodejs\Setup\swix\packages.config" -PackagesDirectory "$packagedir"
59-
exit
72+
73+
# If using the -microbuild switch, ONLY do the microbuild restore (this behavior is expected by the build servers).
74+
if($microbuild) {
75+
exit
76+
}
77+
}
78+
79+
# Deduce the VS install path if not provided
80+
if (-not $vsroot) {
81+
# Can use the registry for Dev14
82+
if ($vstarget -eq "14.0") {
83+
$vspath = Get-ItemProperty -Path "HKLM:\Software\Wow6432Node\Microsoft\VisualStudio\14.0" -EA 0
84+
if (-not $vspath) {
85+
$vspath = Get-ItemProperty -Path "HKLM:\Software\Microsoft\VisualStudio\14.0" -EA 0
86+
}
87+
if ($vspath) {
88+
$vsroot = $vspath.InstallDir
89+
}
90+
}
91+
92+
# Else check the environment
93+
if (-not $vsroot) {
94+
$vsroot = $env:VSINSTALLDIR
95+
}
96+
}
97+
98+
# Check the final value is valid
99+
if (-not $vsroot -or -not (Test-Path -Path $vsroot)) {
100+
Throw "Unable to determine the VS installation directory. Please specify -vsroot."
60101
}
61102

103+
switch($vstarget) {
104+
"14.0" {
105+
$name = "VS 2015"
106+
$msbuildroot = "${env:ProgramFiles(x86)}\MSBuild\Microsoft\VisualStudio\v14.0"
107+
}
108+
"15.0" {
109+
$name = "VS 2017"
110+
$msbuildroot = "${vsroot}\MSBuild\Microsoft\VisualStudio\v15.0"
111+
}
112+
default {
113+
Throw "Invalid -vstarget of ${vstarget} specified"
114+
}
115+
}
116+
117+
# Once to this point, the target version and install path are verified.
118+
119+
Write-Output "Setting up NTVS development environment for ${name}"
120+
Write-Output "============================================================"
121+
62122
# Disable strong name verification for the Node.js Tools binaries
63123
$skipVerificationKey = If ( $ENV:PROCESSOR_ARCHITECTURE -eq "AMD64") {"EnableSkipVerification.reg" } Else {"EnableSkipVerification86.reg" }
64124
$skipVerificationKey = Join-Path $rootDir $("Nodejs\Prerequisites\" + $skipVerificationKey)
65125
Write-Output "Disabling strong name verification for Node.js Tools binaries"
66126
Write-Output " $($skipVerificationKey)"
67127
regedit /s $($skipVerificationKey)
128+
Write-Output ""
68129

130+
$from = "$rootDir\Nodejs\Product\Nodejs\Microsoft.NodejsTools.targets"
131+
$to = "$msbuildroot\Node.js Tools\Microsoft.NodejsTools.targets"
132+
Write-Output "Copying targets file: $($from) -> $($to)"
133+
New-Item -Force $to > $null
134+
Copy-Item -Force $from $to
69135
Write-Output ""
70-
Write-Output "Copying required files"
71-
foreach ($version in $target_versions) {
72-
# Copy Microsoft.NodejsTools.targets file to relevant location
73-
$from = "$rootDir\Nodejs\Product\Nodejs\Microsoft.NodejsTools.targets"
74-
$to = "$($version.msbuildroot)\Node.js Tools\Microsoft.NodejsTools.targets"
75-
Write-Output $version
76-
Write-Output " $($from) -> $($to)"
77-
New-Item -Force $to > $null
78-
Copy-Item -Force $from $to
79-
}
80136

81-
# Install VSTestHost
82-
$shouldInstallVSTestHost = $false
83-
if (-not $skipTestHost) {
84-
Write-Output ""
85-
Write-Output "Installing VSTestHost automation"
86-
$vsTestHostLocation = "$rootDir\Common\Tests\Prerequisites\VSTestHost.msi"
87-
Write-Output " $($vsTestHostLocation)"
88137

89-
# Check installed VSTestHost versions
90-
$gacDir = "${env:windir}\Microsoft.NET\assembly\GAC_MSIL"
91-
foreach ($version in $target_versions) {
138+
# Need to use distinct install processes until the VSTestHost MSI is updated for 15.0.
139+
function InstallDev14TestHost {
140+
$shouldInstallVSTestHost = $false
141+
if (-not $skipTestHost) {
142+
Write-Output ""
143+
$vsTestHostLocation = "$rootDir\Common\Tests\Prerequisites\VSTestHost.msi"
144+
Write-Output " Installing VSTestHost from $($vsTestHostLocation)"
145+
146+
# Check installed VSTestHost versions
147+
$gacDir = "${env:windir}\Microsoft.NET\assembly\GAC_MSIL"
92148
$currentVSTestHost = ls $gacDir -Recurse | ?{$_.Name -eq "Microsoft.VisualStudioTools.VSTestHost.$($version.number).dll"}
93149

94-
$targetVSTestHostVersion = "$($version.number).1.0"
150+
$targetVSTestHostVersion = "14.0.1.0"
95151
if (-not $currentVSTestHost) {
96152
Write-Output "VSTestHost not installed. Installing version $targetVSTestHostVersion"
97153
$shouldInstallVSTestHost = $true
@@ -103,16 +159,34 @@ if (-not $skipTestHost) {
103159
break
104160
}
105161
}
162+
163+
if ($shouldInstallVSTestHost) {
164+
Start-Process msiexec -ArgumentList /i, $vsTestHostLocation, /lv, ${env:temp}\vstesthost.log, /quiet -Wait
165+
Write-Output " Install completed"
166+
} else {
167+
Write-Output " Skipping VSTestHost installation."
168+
}
106169
}
107170

108-
if ($shouldInstallVSTestHost) {
109-
# TODO: This doesn't appear to install correctly on some machines.
110-
Start-Process msiexec -ArgumentList /i, $vsTestHostLocation, /lv, ${env:temp}\vstesthost.log, /quiet -Wait
111-
Write-Output " Install completed"
112-
} else {
113-
Write-Output " Skipping VSTestHost installation (compatible version of VSTestHost already installed.)"
171+
function InstallDev15TestHost {
172+
Write-Output "Installing current VSTestHost build"
173+
$vstesthostdrop = "$rootDir\Common\Tests\Prerequisites\Dev15"
174+
Copy-Item -Force "$vstesthostdrop\Microsoft.VisualStudioTools.VSTestHost.15.0.dll" "${vsroot}\Common7\IDE\CommonExtensions\Platform"
175+
Copy-Item -Force "$vstesthostdrop\Microsoft.VisualStudioTools.VSTestHost.15.0.pkgdef" "${vsroot}\Common7\IDE\CommonExtensions\Platform"
176+
$regroot = mkdir -Force "HKLM:\Software\WOW6432Node\Microsoft\VisualStudio\15.0\EnterpriseTools\QualityTools\HostAdapters\VSTestHost";
177+
$regsupporttest = mkdir -Force "HKLM:$regroot\SupportedTestTypes";
178+
Set-ItemProperty HKLM:$regroot -Name "EditorType" -Value "Microsoft.VisualStudioTools.VSTestHost.TesterTestControl, Microsoft.VisualStudioTools.VSTestHost.15.0, Version=15.0.5.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A";
179+
Set-ItemProperty HKLM:$regroot -Name "Type" -Value "Microsoft.VisualStudioTools.VSTestHost.TesterTestAdapter, Microsoft.VisualStudioTools.VSTestHost.15.0, Version=15.0.5.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A";
180+
Set-ItemProperty HKLM:$regsupporttest -Name "{13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b}" -Value "Unit Test";
181+
}
182+
183+
if (-not $skipTestHost) {
184+
switch ($vstarget) {
185+
"14.0" {InstallDev14TestHost}
186+
"15.0" {InstallDev15TestHost}
187+
}
114188
}
115189

116190
Write-Output ""
117191
Write-Output "Environment configuration succeeded."
118-
Write-Output ""
192+
Write-Output ""

0 commit comments

Comments
 (0)