forked from ProximoSrl/Jarvis.Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchNstore.ps1
119 lines (106 loc) · 6.2 KB
/
SwitchNstore.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function Edit-XmlNodes {
param (
[xml] $doc = $(throw "doc is a required parameter"),
[string] $xpath = $(throw "xpath is a required parameter"),
$namespace = $(throw "namespace is a required parameter"),
[string] $value = $(throw "value is a required parameter"),
[bool] $condition = $true
)
if ($condition -eq $true) {
$nodes = $doc.SelectNodes($xpath, $namespace)
foreach ($node in $nodes) {
if ($node -ne $null) {
if ($node.NodeType -eq "Element") {
$node.InnerXml = $value
}
else {
$node.Value = $value
}
}
}
}
}
function Switch-FrameworkReference {
param (
[String] $sourcePrj = $(throw "sourcePrj is a required parameter")
#[string] $destinationDir = $(throw "= is a required parameter")
)
$frameworkLocation = (get-item $sourcePrj ).parent.FullName
Get-ChildItem "$sourcePrj" -Filter *.csproj -Recurse |
Foreach-Object {
if ($_.FullName.Contains("Jarvis.Web"))
{
Write-Output 'Modification of project $_.FullName'
$xml = [xml](Get-Content $_.FullName)
$ns = new-object Xml.XmlNamespaceManager $xml.NameTable
$ns.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003")
Edit-XmlNodes -doc $xml -namespace $ns `
-xpath "//msb:Reference[starts-with(@Include, 'Jarvis.Framework.Shared,')]" `
-value "<SpecificVersion>False</SpecificVersion>
<HintPath>$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Shared.dll</HintPath>
"
Edit-XmlNodes -doc $xml -namespace $ns `
-xpath "//msb:Reference[starts-with(@Include, 'Jarvis.NEventStoreEx,')]" `
-value "<SpecificVersion>False</SpecificVersion>
<HintPath>$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.NEventStoreEx.dll</HintPath>
"
Edit-XmlNodes -doc $xml -namespace $ns `
-xpath "//msb:Reference[starts-with(@Include, 'Jarvis.Framework.Kernel,')]" `
-value "<SpecificVersion>False</SpecificVersion>
<HintPath>$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Kernel.dll</HintPath>
"
Edit-XmlNodes -doc $xml -namespace $ns `
-xpath "//msb:Reference[starts-with(@Include, 'Jarvis.Framework.Bus.Rebus.Integration,')]" `
-value "<SpecificVersion>False</SpecificVersion>
<HintPath>$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Bus.Rebus.Integration.dll</HintPath>
"
Edit-XmlNodes -doc $xml -namespace $ns `
-xpath "//msb:Reference[starts-with(@Include, 'Jarvis.Framework.TestHelpers,')]" `
-value "<SpecificVersion>False</SpecificVersion>
<HintPath>$frameworkLocation\Jarvis.Framework\Jarvis.Framework.TestHelpers\bin\Debug\net461\Jarvis.Framework.TestHelpers.dll</HintPath>
"
$xml.Save($_.FullName)
}
else
{
Write-Output 'Modification of project $_.FullName'
$xml = [xml](Get-Content $_.FullName)
$referenceNode = $xml.SelectSingleNode("//ItemGroup/PackageReference[@Include='Jarvis.Framework']")
if ($referenceNode -ne $null) { $referenceNode.ParentNode.RemoveChild($referenceNode)}
$referenceNode = $xml.SelectSingleNode("//ItemGroup/PackageReference[@Include='Jarvis.Framework.Shared']")
if ($referenceNode -ne $null) { $referenceNode.ParentNode.RemoveChild($referenceNode)}
$referenceNode = $xml.SelectSingleNode("//ItemGroup/PackageReference[@Include='Jarvis.Framework.Rebus']")
if ($referenceNode -ne $null) { $referenceNode.ParentNode.RemoveChild($referenceNode)}
$firstChild = $xml
$itemGroup = $xml.CreateElement("ItemGroup")
$kernelReference = $xml.CreateElement("Reference")
$attrib = $xml.CreateAttribute("Include")
$attrib.Value = "Jarvis.Framework.Kernel"
$kernelReference.Attributes.Append($attrib)
$kernelHintPath = $xml.CreateElement("HintPath")
$kernelHintPath.InnerText = "$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Kernel.dll"
$kernelReference.AppendChild($kernelHintPath)
$itemGroup.AppendChild($kernelReference)
$sharedReference = $xml.CreateElement("Reference")
$sharedattrib = $xml.CreateAttribute("Include")
$sharedattrib.Value = "Jarvis.Framework.Shared"
$sharedReference.Attributes.Append($sharedattrib)
$sharedHintPath = $xml.CreateElement("HintPath")
$sharedHintPath.InnerText = "$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Shared.dll"
$sharedReference.AppendChild($sharedHintPath)
$itemGroup.AppendChild($sharedReference)
$rebusReference = $xml.CreateElement("Reference")
$rebusattrib = $xml.CreateAttribute("Include")
$rebusattrib.Value = "Jarvis.Framework.Bus.Rebus.Integration"
$rebusReference.Attributes.Append($rebusattrib)
$rebusHintPath = $xml.CreateElement("HintPath")
$rebusHintPath.InnerText = "$frameworkLocation\Jarvis.Framework\Jarvis.Framework.Bus.Rebus.Integration\bin\Debug\net461\Jarvis.Framework.Bus.Rebus.Integration.dll"
$rebusReference.AppendChild($rebusHintPath)
$itemGroup.AppendChild($rebusReference)
$xml.DocumentElement.AppendChild($itemGroup)
$xml.Save($_.FullName)
}
}
}
$runningDirectory = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
Switch-FrameworkReference -sourcePrj $runningDirectory