forked from Fody/MethodDecorator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
94 lines (76 loc) · 2.31 KB
/
install.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
param($installPath, $toolsPath, $package, $project)
function RemoveForceProjectLevelHack($project)
{
Write-Host "RemoveForceProjectLevelHack"
Foreach ($item in $project.ProjectItems)
{
if ($item.Name -eq "Fody_ToBeDeleted.txt")
{
$item.Delete()
}
}
}
function FlushVariables()
{
Write-Host "Flushing environment variables"
$env:FodyLastProjectPath = ""
$env:FodyLastWeaverName = ""
$env:FodyLastXmlContents = ""
}
function Update-FodyConfig($addinName, $project)
{
Write-Host "Update-FodyConfig"
$fodyWeaversPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($project.FullName), "FodyWeavers.xml")
$FodyLastProjectPath = $env:FodyLastProjectPath
$FodyLastWeaverName = $env:FodyLastWeaverName
$FodyLastXmlContents = $env:FodyLastXmlContents
if (
($FodyLastProjectPath -eq $project.FullName) -and
($FodyLastWeaverName -eq $addinName))
{
Write-Host "Upgrade detected. Restoring content for $addinName"
[System.IO.File]::WriteAllText($fodyWeaversPath, $FodyLastXmlContents)
FlushVariables
return
}
FlushVariables
$xml = [xml](get-content $fodyWeaversPath)
$weavers = $xml["Weavers"]
$node = $weavers.SelectSingleNode($addinName)
if (-not $node)
{
Write-Host "Appending node"
$newNode = $xml.CreateElement($addinName)
$weavers.AppendChild($newNode)
}
$xml.Save($fodyWeaversPath)
}
function Fix-ReferencesCopyLocal($package, $project)
{
Write-Host "Fix-ReferencesCopyLocal $($package.Id)"
$asms = $package.AssemblyReferences | %{$_.Name}
foreach ($reference in $project.Object.References)
{
if ($asms -contains $reference.Name + ".dll")
{
if($reference.CopyLocal -eq $true)
{
$reference.CopyLocal = $false;
}
}
}
}
function UnlockWeaversXml($project)
{
$fodyWeaversProjectItem = $project.ProjectItems.Item("FodyWeavers.xml");
if ($fodyWeaversProjectItem)
{
$fodyWeaversProjectItem.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}")
$fodyWeaversProjectItem.Save()
$fodyWeaversProjectItem.Document.Close()
}
}
UnlockWeaversXml($project)
RemoveForceProjectLevelHack $project
Update-FodyConfig $package.Id.Replace(".Fody", "") $project
Fix-ReferencesCopyLocal $package $project