-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude-input.ps1
More file actions
78 lines (68 loc) · 2.09 KB
/
Copy pathinclude-input.ps1
File metadata and controls
78 lines (68 loc) · 2.09 KB
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
function script:CreateNodes {
[CmdletBinding()]
param (
[Parameter()] [xml] $root,
[Parameter()] $parent,
[Parameter()] $tree
)
if ($tree -is [hashtable]) {
return $tree.keys | ForEach-Object {
if ($_.StartsWith("@")) {
$attr = $root.CreateAttribute($_.Substring(1))
$attr.Value = $tree[$_]
$parent.SetAttributeNode($attr);
return @()
}
$current = $root.CreateElement($_)
$null = (script:CreateNodes $root $current $tree[$_]) | ForEach-Object {
if ($_ -is [System.Xml.XmlAttribute]) {
# Skip
}
else {
$current.AppendChild($_)
}
}
return $current
}
}
else {
$parent.InnerText = $tree
return @()
}
}
$projectList = Get-ChildItem -Recurse -Filter *.csproj
$index = 0
$max = $projectList.Length
$found = 0
$added = 0
$projectList | ForEach-Object {
$target = $_.FullName
$index = $index + 1
$pct = [int](($index / $max) * 100)
Write-Host "$target ($pct %) `r" -NoNewline
[xml] $x = Get-Content -Path $target
Get-ChildItem -Filter *.txt -Path $_.DirectoryName | ForEach-Object {
$found = $found + 1
$file = $_.Name
$current = $x.SelectSingleNode("//None[@Update = '$file']")
if (-not $current) {
$added = $added + 1
$n = script:CreateNodes $x $x.Project @{
ItemGroup = @{
None = @{
"@Update" = $file
CopyToOutputDirectory = "Always"
}
}
}
$null = $x.Project.AppendChild($n)
$null = $x.Save($target)
}
}
}
$c = "`e[33;1m"
$r = "`e[0m"
Write-Host ""
Write-Host "Scanned $($c)$max$r projects"
Write-Host "`tFound $c$($found.ToString().PadLeft(3, ' '))$r txt files"
Write-Host "`tAdded $c$($added.ToString().PadLeft(3, ' '))$r txt files"