-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
39 lines (34 loc) · 1.44 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
using namespace Microsoft.PowerShell.Commands
[CmdletBinding()]
param(
[ValidateSet("CurrentUser", "AllUsers")]
$Scope = "CurrentUser",
$Task = 'Build'
)
[ModuleSpecification[]]$RequiredModules = Import-LocalizedData -BaseDirectory $PSScriptRoot -FileName RequiredModules
$Policy = (Get-PSRepository PSGallery).InstallationPolicy
Set-PSRepository PSGallery -InstallationPolicy Trusted
try {
$RequiredModules | ForEach-Object {
if ( !( ($null -eq (Get-Module -Name $_.Name -ListAvailable)) ) ) {
if ((Get-Module -Name $_.Name -ListAvailable).Version.ToString() -ne $_.RequiredVersion) {
try {
Remove-Module -Name $_.Name -Force -ErrorAction SilentlyContinue
}
catch {
$thiserror = $_
Write-Warning ("Problem: {0}`r`n{1}" -f $thiserror.Exception.Message, $thiserror.ScriptStackTrace)
}
Install-Module -Name $_.Name -RequiredVersion $_.RequiredVersion -Scope $Scope -Repository PSGallery -SkipPublisherCheck -ErrorAction SilentlyContinue -Force
}
}
else {
Install-Module -Name $_.Name -RequiredVersion $_.RequiredVersion -Scope $Scope -Repository PSGallery -SkipPublisherCheck -ErrorAction SilentlyContinue -Force
}
}
}
finally {
Set-PSRepository PSGallery -InstallationPolicy $Policy
}
$RequiredModules | Import-Module
Invoke-Build -Task $Task