forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.ps1
116 lines (97 loc) · 3.99 KB
/
check.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Check prereqs for Script Runtime
# prints diagnostic messages.
function Check([string] $componentName, [string] $verstr, [Version] $requiredVersion)
{
if ($verStr[0] -eq "v") # trim leading 'v'
{
$verStr = $verStr.Substring(1)
}
# Version could be a beta, like 2.1.200-preview-007576
$x = $verstr;
$idxDash = $x.IndexOf('-')
if ($idxDash -gt 0) {
$x = $x.Substring(0, $idxDash)
}
$actualVersion = [Version]::Parse($x)
$msg = $componentName + " " + $verstr;
if ($actualVersion -lt $requiredVersion)
{
Write-Host ("[X] " + $msg +". Error. Must be at least major version " + $requiredVersion) -ForegroundColor Red
return $false
} else {
Write-Host -NoNewline ("[*] " + $msg) -foreground "green"
Write-Host " (must be at least" $requiredVersion ")"
return $true
}
}
Write-Host "Checking dependencies"
# Check VS
# Use vswhere, which is installed with VS 15.2 and later. https://github.com/Microsoft/vswhere
$x= [Environment]::ExpandEnvironmentVariables("%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe")
if(![System.IO.File]::Exists($x)){
Write-Host " VSWhere is missing. Is VS 2017 installed? See https://www.visualstudio.com/downloads/ " -ForegroundColor Red
} else {
$installedVersions = & $x -property catalog_buildVersion
# could be either a string or an array of strings.
if ($installedVersions -is [array]) {
# as an array, take the latest version on the machine
$latest = [Version]::Parse($installedVersions[0])
Write-Host " Multiple VS versions installed:"
foreach($ver in $installedVersions) {
$verCurrent = [Version]::Parse($ver)
Write-Host " " $verCurrent
if ($verCurrent -gt $latest) {
$latest = $verCurrent
}
}
} else {
$latest = $installedVersions;
}
$ok = Check "VS 2017" ($latest.ToString()) ([Version]::Parse("15.7.0"))
if (-Not $ok) {
Write-Host " You can update VS from the Tools | Extensions and Updates menu."
}
}
# Check dotnet
# C:\dev\AFunc\script-core3>dotnet --version
# 2.0.0
$actualVersion = & "dotnet" --version
$ok = Check "dotnet" $actualVersion ([Version]::Parse("2.1.300"))
if (-Not $ok) {
Write-Host "You can update by installing '.NET Core 2.1 SDK' from https://www.microsoft.com/net/download/windows"
Write-Host
}
# Check Node
$actualVersion = & "node" -v
$ok = Check "node" $actualVersion ([Version]::Parse("8.4.0"))
if (-Not $ok) {
Write-Host " You can update node by downloading the latest from https://nodejs.org"
Write-Host
}
# Check NPM
$actualVersion = & "npm" -v
$ok = Check "npm" $actualVersion ([Version]::Parse("5.0"))
if (-Not $ok) {
Write-Host "You can upgrade npm by running: "
Write-Host " npm install -g npm@latest"
Write-Host
}
# Check Java
$javaFullVersion = & "java" -version 2>&1
$javaVersion = $javaFullVersion[0].toString().Split(' ')
$javaVersion = $javaVersion[2].Trim('"')
$underscoreIndex = $javaVersion.IndexOf('_')
$actualVersion = $javaVersion.Substring(0, $underscoreIndex)
$ok = Check "java" $actualVersion ([Version]::Parse("1.8.0"))
if (-Not $ok) {
Write-Host " You can udpate java by downloading from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html"
Write-Host
}
$ok = Test-Path 'env:JAVA_HOME'
if (-Not $ok) {
Write-Host "JAVA_HOME Environment variable not set. Set it to JDK folder. Example c:\Program Files\Java\jdk1.8.0_171" -ForegroundColor Red
Write-Host
}
# See here for hints on doing Devenv detection:
# https://stackoverflow.com/questions/42435592/determining-installed-visual-studio-path-for-2017
# Or here: https://stackoverflow.com/questions/40694598/how-do-i-call-visual-studio-2017-rcs-version-of-msbuild-from-a-bat-file/40702534#40702534