Skip to content

Commit 34bfc47

Browse files
author
Jeff Treuting
committed
Cleaned up the Install.ps1 scripts
1 parent ba30e55 commit 34bfc47

6 files changed

Lines changed: 64 additions & 122 deletions

File tree

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Install.ps1
22
param($installPath, $toolsPath, $package, $project)
33

4+
# Settings
5+
$parentPath = "configuration/sharpRepository/repositories"
6+
$keyPath = "repository[@name='cacheRepository']"
7+
48
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
59
{
10+
$xml = New-Object xml
11+
612
# load config as XML
713
$xml.Load($localPath)
814

@@ -14,7 +20,7 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
1420

1521
if ($nodes.Count -gt 0)
1622
{
17-
# if there are multiple repository names with same key, then the NuGet update added the additional ones and they will be last
23+
# if there are multiple repository names with the same key, then the NuGet update added the additional ones and they will be last
1824
# so loop through those nodes, excluding the first one, and remove them
1925
$i = 1;
2026
while ($i -lt $nodes.Count)
@@ -26,30 +32,16 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2632
# save the config file
2733
$xml.Save($localPath)
2834
}
29-
30-
}
31-
32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
37-
{
38-
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
40-
41-
# clean duplicate entries
42-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='cacheRepository']"
4335
}
4436

45-
# find the App.config file if there is one
46-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
47-
if ($config -ne $null)
37+
# find the Web.config/App.config file if there is one
38+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
39+
Foreach ($item in $items)
4840
{
4941
# find its path on the file system
50-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
42+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
5143

5244
# clean duplicate entries
53-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='cacheRepository']"
45+
Clean-Dups-In-Config-File $localPath.Value $parentPath $keyPath
5446
}
5547

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Install.ps1
22
param($installPath, $toolsPath, $package, $project)
33

4+
# Settings
5+
$parentPath = "configuration/sharpRepository/cachingProviders"
6+
$keyPath = "cachingProvider[@name='memCachedProvider']"
7+
48
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
59
{
10+
$xml = New-Object xml
11+
612
# load config as XML
713
$xml.Load($localPath)
814

@@ -26,30 +32,15 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2632
# save the config file
2733
$xml.Save($localPath)
2834
}
29-
3035
}
3136

32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
37+
# find the Web.config/App.config file if there is one
38+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
39+
Foreach ($item in $items)
3740
{
3841
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
42+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
4043

4144
# clean duplicate entries
42-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingProviders" "cachingProvider[@name='memCachedProvider']"
45+
Clean-Dups-In-Config-File $localPath.Value $parentPath $keyPath
4346
}
44-
45-
# find the App.config file if there is one
46-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
47-
if ($config -ne $null)
48-
{
49-
# find its path on the file system
50-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
51-
52-
# clean duplicate entries
53-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingProviders" "cachingProvider[@name='memCachedProvider']"
54-
}
55-
Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Install.ps1
22
param($installPath, $toolsPath, $package, $project)
33

4+
# Settings
5+
$parentPath = "configuration/sharpRepository/cachingProviders"
6+
$keyPath = "cachingProvider[@name='redisProvider']"
7+
48
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
59
{
10+
$xml = New-Object xml
11+
612
# load config as XML
713
$xml.Load($localPath)
814

@@ -26,30 +32,15 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2632
# save the config file
2733
$xml.Save($localPath)
2834
}
29-
3035
}
3136

32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
37+
# find the Web.config/App.config file if there is one
38+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
39+
Foreach ($item in $items)
3740
{
3841
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
42+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
4043

4144
# clean duplicate entries
42-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingProviders" "cachingProvider[@name='redisProvider']"
45+
Clean-Dups-In-Config-File $localPath.Value $parentPath $keyPath
4346
}
44-
45-
# find the App.config file if there is one
46-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
47-
if ($config -ne $null)
48-
{
49-
# find its path on the file system
50-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
51-
52-
# clean duplicate entries
53-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingProviders" "cachingProvider[@name='redisProvider']"
54-
}
55-
Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Install.ps1
22
param($installPath, $toolsPath, $package, $project)
33

4+
# Settings
5+
$parentPath = "configuration/sharpRepository/repositories"
6+
$keyPath = "repository[@name='ef5Repository']"
7+
48
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
59
{
10+
$xml = New-Object xml
11+
612
# load config as XML
713
$xml.Load($localPath)
814

@@ -26,30 +32,15 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2632
# save the config file
2733
$xml.Save($localPath)
2834
}
29-
3035
}
3136

32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
37+
# find the Web.config/App.config file if there is one
38+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
39+
Foreach ($item in $items)
3740
{
3841
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
42+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
4043

4144
# clean duplicate entries
42-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='ef5Repository']"
45+
Clean-Dups-In-Config-File $localPath.Value $parentPath $keyPath
4346
}
44-
45-
# find the App.config file if there is one
46-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
47-
if ($config -ne $null)
48-
{
49-
# find its path on the file system
50-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
51-
52-
# clean duplicate entries
53-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='ef5Repository']"
54-
}
55-
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Install.ps1
22
param($installPath, $toolsPath, $package, $project)
33

4+
# Settings
5+
$parentPath = "configuration/sharpRepository/repositories"
6+
$keyPath = "repository[@name='inMemoryRepository']"
7+
48
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
59
{
10+
$xml = New-Object xml
11+
612
# load config as XML
713
$xml.Load($localPath)
814

@@ -14,7 +20,7 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
1420

1521
if ($nodes.Count -gt 0)
1622
{
17-
# if there are multiple repository names with same key, then the NuGet update added the additional ones and they will be last
23+
# if there are multiple repository names with the same key, then the NuGet update added the additional ones and they will be last
1824
# so loop through those nodes, excluding the first one, and remove them
1925
$i = 1;
2026
while ($i -lt $nodes.Count)
@@ -26,30 +32,16 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2632
# save the config file
2733
$xml.Save($localPath)
2834
}
29-
30-
}
31-
32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
37-
{
38-
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
40-
41-
# clean duplicate entries
42-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='inMemoryRepository']"
4335
}
4436

45-
# find the App.config file if there is one
46-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
47-
if ($config -ne $null)
37+
# find the Web.config/App.config file if there is one
38+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
39+
Foreach ($item in $items)
4840
{
4941
# find its path on the file system
50-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
42+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
5143

5244
# clean duplicate entries
53-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/repositories" "repository[@name='inMemoryRepository']"
45+
Clean-Dups-In-Config-File $localPath.Value $parentPath $keyPath
5446
}
5547

nuget/SharpRepository.Repository/tools/Install.ps1

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ param($installPath, $toolsPath, $package, $project)
33

44
Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
55
{
6+
$xml = New-Object xml
7+
68
# load config as XML
79
$xml.Load($localPath)
810

@@ -14,7 +16,7 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
1416

1517
if ($nodes.Count -gt 0)
1618
{
17-
# if there are multiple repository names with same key, then the NuGet update added the additional ones and they will be last
19+
# if there are multiple repository names with the same key, then the NuGet update added the additional ones and they will be last
1820
# so loop through those nodes, excluding the first one, and remove them
1921
$i = 1;
2022
while ($i -lt $nodes.Count)
@@ -26,34 +28,17 @@ Function Clean-Dups-In-Config-File ($localPath, $parentNodePath, $nodePath)
2628
# save the config file
2729
$xml.Save($localPath)
2830
}
29-
3031
}
3132

32-
$xml = New-Object xml
33-
34-
# find the Web.config file if there is one
35-
$config = $project.ProjectItems | where {$_.Name -eq "Web.config" }
36-
if ($config -ne $null)
33+
# find the Web.config/App.config file if there is one
34+
$items = $project.ProjectItems | where {$_.Name -eq "Web.config" -or $_.Name -eq "App.config" }
35+
Foreach ($item in $items)
3736
{
3837
# find its path on the file system
39-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
38+
$localPath = $item.Properties | where {$_.Name -eq "LocalPath"}
4039

4140
# clean duplicate entries
4241
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='standardCachingStrategy']"
4342
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='timeoutCachingStrategy']"
4443
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='noCaching']"
4544
}
46-
47-
# find the App.config file if there is one
48-
$config = $project.ProjectItems | where {$_.Name -eq "App.config" }
49-
if ($config -ne $null)
50-
{
51-
# find its path on the file system
52-
$localPath = $config.Properties | where {$_.Name -eq "LocalPath"}
53-
54-
# clean duplicate entries
55-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='standardCachingStrategy']"
56-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='timeoutCachingStrategy']"
57-
Clean-Dups-In-Config-File $localPath.Value "configuration/sharpRepository/cachingStrategies" "cachingStrategy[@name='noCaching']"
58-
}
59-

0 commit comments

Comments
 (0)