-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-nf-build-components.ps1
144 lines (115 loc) · 4.85 KB
/
install-nf-build-components.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# Copyright (c) .NET Foundation and Contributors.
# See LICENSE file in the project root for full license information.
#
function DownloadVsixFile($fileUrl, $downloadFileName)
{
Write-Debug "Download VSIX file from $fileUrl to $downloadFileName"
Invoke-WebRequest -Uri $fileUrl -OutFile $downloadFileName
}
"INFO: Downloading extension details" | Write-Host
[bool]$isPreview = $env:USE_PREVIEW
$tempDir = $env:RUNNER_TEMP
# Find which VS version is installed
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"
"INFO: VsWherePath is: $VsWherePath" | Write-Host
$VsInstance = $(&$VSWherePath -latest -property displayName)
"INFO: VS is: $VsInstance" | Write-Host
# handle preview version
if($isPreview -eq $true)
{
Write-Host "*** Installing preview version of the extension ***"
# get extension information from Open VSIX Gallery feed
$vsixFeedXml = Join-Path $($tempDir) "vs-extension-feed.xml"
Invoke-WebRequest -Uri "https://www.vsixgallery.com/feed/author/nanoframework" -OutFile $vsixFeedXml
[xml]$feedDetails = Get-Content $vsixFeedXml
# Define the extension IDs
$vs2019Id = "455f2be5-bb07-451e-b351-a9faf3018dc9"
$vs2022Id = "bf694e17-fa5f-4877-9317-6d3664b2689a"
# feed list VS2019 and VS2022 extensions using the extension ID
# VS2022
if($vsInstance.Contains('2022'))
{
$vs2022Entry = $feedDetails.feed.entry | Where-Object { $_.Vsix.Id -eq $vs2022Id }
if($vs2022Entry)
{
$extensionUrl = $vs2022Entry.content.src
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
$extensionVersion = $vs2022Entry.Vsix.Version
}
else
{
Write-Host "ERROR: VS2022 extension with ID $vs2022Id not found."
}
}
elseif($vsInstance.Contains('2019'))
{
$vs2019Entry = $feedDetails.feed.entry | Where-Object { $_.Vsix.Id -eq $vs2019Id }
if($vs2019Entry)
{
$extensionUrl = $vs2019Entry.content.src
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
$extensionVersion = $vs2019Entry.Vsix.Version
}
else
{
Write-Host "ERROR: VS2019 extension with ID $vs2019Id not found."
}
}
}
else
{
# Build headers for the request
$headers = @{
"User-Agent" = "request"
"Accept" = "application/vnd.github.v3+json"
"ContentType" = "application/json"
}
if($gitHubToken)
{
Write-Host "INFO: Adding authentication header"
$headers["Authorization"] = "Bearer $gitHubToken"
}
Write-Host "INFO: Get latest releases of nanoFramework VS extension from GitHub"
# Use Invoke-WebRequest to get the release JSON
$response = Invoke-WebRequest -Uri 'https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=10' -Headers $headers
# Convert the response content to JSON objects
$releases = $response.Content | ConvertFrom-Json
# Filter out draft releases
$finalReleases = $releases | Where-Object { -not $_.draft }
# Extract tags using the tag_name property
$vs2022Release = $finalReleases | Where-Object { $_.tag_name -match '^v2022\.\d+\.\d+\.\d+$' } | Select-Object -First 1
if($vs2022Release)
{
$vs2022Tag = $vs2022Release.tag_name
}
$vs2019Release = $finalReleases | Where-Object { $_.tag_name -match '^v2019\.\d+\.\d+\.\d+$' } | Select-Object -First 1
if($vs2019Release)
{
$vs2019Tag = $vs2019Release.tag_name
}
# Get extension details according to VS version, starting from VS2022 down to VS2019
if($vsInstance.Contains('2022'))
{
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix"
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
$extensionVersion = $vs2022Tag
}
elseif($vsInstance.Contains('2019'))
{
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix"
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
$extensionVersion = $vs2019Tag
}
}
# Download VS extension
DownloadVsixFile $extensionUrl $vsixPath
# Unzip extension
Write-Host "INFO: Unzip VS extension content"
Expand-Archive -LiteralPath $vsixPath -DestinationPath $tempDir\nf-extension\
# copy build files to msbuild location
$VsPath = $(&$VsWherePath -latest -property installationPath)
Write-Host "INFO: Copying build files to msbuild location"
$msbuildPath = $VsPath + "\MSBuild"
Copy-Item -Path "$tempDir\nf-extension\`$MSBuild\nanoFramework" -Destination $msbuildPath -Recurse
Write-Output "INFO: Installed VS extension $extensionVersion"