-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemp.ps1
96 lines (92 loc) · 2.63 KB
/
temp.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
#todo: can has resolve? restore needed?
function GetCsprojPath {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $true,
#ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)]
[Alias('FullName')]
[string]$Path
)
BEGIN {
$projectPattern = '^Project\('
$filenameIndex = 2
}
PROCESS {
Write-Verbose "GetCsprojPath input: '$Path'"
$directory = Split-Path $Path
Get-Content $Path |
Select-String $projectPattern |
ForEach-Object {
$projectPath = ($_ -split '[=,]')[$filenameIndex].Trim(' "')
$output = Join-Path $directory $projectPath
Write-Verbose "GetCsprojPath project file: $output"
if ($output -match '\.csproj$') {
[PSCustomObject]@{
Path = $output
}
}
}
}
END {}
}
function GetPackageNameVersion {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)]
[Alias('FullName')]
[string]$Path
)
BEGIN {}
PROCESS {
Write-Verbose "GetPackageNameVersion input: $Path"
if (Test-Path $Path) {
$xml = [xml](Get-Content $Path)
Select-Xml -Xml $xml -XPath '//PackageReference' |
select -ExpandProperty Node |
ForEach-Object {
$output = [PSCustomObject]@{
Name = $_.Include
Version = $_.Version
}
Write-Verbose "GetPackageNameVersion output: $output"
$output
}
}
}
END {}
}
function GetNuGetPackageDirectory {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[PSCustomObject]$NameVersion
)
BEGIN {
#todo: add logic here, for nuget.config n stuff
$nugetDefaultFolder = "$HOME\.nuget\packages"
}
PROCESS {
Write-Verbose "GetNugetPackageDirectory input: $Path"
$output = [PSCustomObject]@{
Path = "$nugetDefaultFolder\$($NameVersion.Name)\$($NameVersion.Version)"
}
Write-Verbose "GetNugetPackageDirectory output: $output"
$output
}
END {}
}
Get-ChildItem -File -Recurse -Filter '*.sln' -ErrorAction SilentlyContinue |
GetCsprojPath -Verbose |
GetPackageNameVersion -Verbose |
GetNuGetPackageDirectory -Verbose
#