forked from roslynpad/roslynpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.ps1
61 lines (47 loc) · 1.84 KB
/
Common.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
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
function Get-DirectoryBuildProps {
$propsFile = Join-Path $PSScriptRoot '..' '.\Directory.Build.props'
return [xml] (Get-Content $propsFile)
}
function Get-TargetFramework {
return (Get-DirectoryBuildProps).Project.PropertyGroup.DefaultTargetFramework
}
function Get-RoslynPadVersion($PatchVersion) {
$versionString = (Get-DirectoryBuildProps).Project.PropertyGroup.RoslynPadVersion
if ($PatchVersion) {
$version = [Version] $versionString
$version = [Version]::new($version.Major, $version.Minor, $PatchVersion)
$versionString = $version.ToString()
}
return $versionString
}
function Get-PackageRoot {
param (
[switch] $Avalonia,
[switch] $Published
)
$project = if ($Avalonia) { 'RoslynPad.Avalonia' } else { 'RoslynPad' }
$targetFramework = if ($Avalonia) { Get-TargetFramework } else { "$(Get-TargetFramework)-windows" }
$path = if ($Published) { "bin\Release\$targetFramework\win-x64\publish" } else { "bin\Release\$targetFramework" }
return (Resolve-Path "$PSScriptRoot\..\src\$project\$path").Path
}
function Get-PackageFiles($RootPath) {
$exclude = @();
$files = Get-ChildItem "$rootPath\*.*" -file |
Where-Object { $exclude -notcontains $_.Name } |
Select-Object -ExpandProperty FullName
if (Test-Path "$rootPath\runtimes") {
$files += Get-ChildItem "$rootPath\runtimes\*.*" -Recurse -File | Select-Object -ExpandProperty FullName
}
return $files
}
function Get-LatestVersionPath($Path) {
$version = Get-ChildItem -Directory -Path $Path |
ForEach-Object { $version = $null; [Version]::TryParse($_.Name, [ref] $version) | Out-Null; $version } |
Sort-Object -Descending | Select-Object -First 1
if (!$version) {
throw "Unable to find a versioned directory under $Path"
}
return $version
}