-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.ps1
93 lines (73 loc) · 2.76 KB
/
build.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
function BuildDotnet ($solution, $dotnetBuild, $outputDirectory)
{
Write-Host "Building $solution..."
# create folder
$outFolder = (New-Item -Name "$outputDirectory/utils/$solution" -ItemType Directory -Force).ToString()
# unpack in folder
Get-ChildItem "$solution.sln" -Recurse | ForEach-Object {
nuget restore $PSItem.FullName
if ($dotnetBuild)
{
Write-Host "Building with dotnet"
dotnet build $PSItem.FullName -o $outFolder
}
else
{
Write-Host "Building with msbuild"
msbuild $PSItem.FullName /p:OutDir=$outFolder
}
}
}
# check if this is running on Azure Pipeline
$IsAzurePipelines = $env:Agent_HomeDirectory + $env:Build_BuildNumber
# only need these modules if not running on Azure Pipeline
if(-Not $env:TF_BUILD)
{
"Installing VSSetup PS1 module" | Write-Host
Install-Module VSSetup -Scope CurrentUser -Force
"Installing BuildUtils PS1 module" | Write-Host
Install-Module BuildUtils -Scope CurrentUser -Force
# get location for msbuild and setup alias
$msbuildLocation = Get-LatestMsbuildLocation
set-alias msbuild $msbuildLocation
}
## Defining variables
$outputDirectory = "dist"
## Setup nanoFirmwareFlasher
$solution = "nanoFirmwareFlasher"
# skip build if running on Azure Pipeline
if(-Not $env:TF_BUILD)
{
"Setup build for $solution" | Write-Host
BuildDotnet $solution $true $outputDirectory
}
## Setup nanoFrameworkDeployer
$solution = "nanoFrameworkDeployer"
# skip build if running on Azure Pipeline
if(-Not $env:TF_BUILD)
{
"Setup build for $solution" | Write-Host
BuildDotnet $solution $false $outputDirectory
}
## Setup nanoFrameworkSDK
$extName = "VS2019ext"
$vsExtensionVersion = "v2019.10.0.2"
"Downloading VS2019 Extension..." | Write-Host
Invoke-WebRequest -Uri "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vsExtensionVersion/nanoFramework.Tools.VS2019.Extension.vsix" -Out "$extName.zip"
Expand-Archive "$extName.zip" -Force
Get-ChildItem '$MSBuild' -Directory -Recurse | ForEach-Object {
$SDKPath = Join-Path -Path $PSItem.FullName -ChildPath "nanoFramework"
Copy-Item -Path $SDKPath -Destination "$outputDirectory/utils/" -Recurse -Force
}
# Clean nanoFramework SDK resources
Remove-Item "$extName.zip"
Remove-Item $extName -Recurse -Force
## Setup nuget
$nugetFolder = (New-Item -Name "$outputDirectory/utils/nuget" -ItemType Directory -Force).ToString()
"Downloading nuget CLI..." | Write-Host
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -Out "$nugetFolder/nuget.exe"
if ($IsMacOS -or $IsLinux)
{
Write-Output "Adding executable rights to utils folder on Unix"
chmod -R +x ./$outputDirectory/utils/
}