forked from YAXLib/YAXLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenRelBins.ps1
89 lines (72 loc) · 2.78 KB
/
GenRelBins.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
# You do NOT need to run this script.
# This is for creating the binaries signed
# with another key, which is only available
# in the main developer's machine.
# Although it's harmless, running this by
# others would fail this very custom build.
param (
[string] $key = "../../_SinaKey/Sina.Libs.pfx",
[string] $src = "YAXLib/YAXLib.csproj",
[string] $dst = "YAXLib/~deploy~.msbuild")
$msb = "$env:windir\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
if(!(Test-Path $msb))
{
$msb = "$env:windir\Microsoft.NET\Framework\v3.5\msbuild.exe"
if(!(Test-Path $msb))
{
Write-Error "MSBuild not found!"
exit 1
}
}
$scrPath = $MyInvocation.MyCommand.Definition
$scrDir = [System.IO.Path]::GetDirectoryName($scrPath)
$src = [System.IO.Path]::Combine($scrDir, $src)
if(!(Test-Path $src))
{
Write-Error "The specified source file not found!"
exit 1
}
$dst = [System.IO.Path]::Combine($scrDir, $dst)
$dstDir = [System.IO.Path]::GetDirectoryName($dst)
$fullkey = [System.IO.Path]::Combine($dstDir, $key)
if(!(Test-Path $fullkey))
{
Write-Error "The specified key file not found!"
exit 1
}
Copy-Item $src $dst
# now read and replace patterns in dst
$patSign = "\<\s*SignAssembly\s*\>(?<value>[^\<]+)\<\/\s*SignAssembly\s*\>"
$patKey = "\<\s*AssemblyOriginatorKeyFile\s*\>(?<value>[^\<]+)\<\/\s*AssemblyOriginatorKeyFile\s*\>"
$patOut = "\<\s*OutputPath\s*\>(?<value>[^\<]+)\<\/\s*OutputPath\s*\>"
$patDoc = "\<\s*DocumentationFile\s*\>(?<value>[^\<]+)\<\/\s*DocumentationFile\s*\>"
$regexSign = [regex]$patSign
$regexKey = [regex]$patKey
$regexOut = [regex]$patOut
$regexDoc = [regex]$patDoc
$text = [System.IO.File]::ReadAllText($dst)
$text = $regexSign.Replace($text, "<SignAssembly>true</SignAssembly>")
$text = $regexKey.Replace($text, "<AssemblyOriginatorKeyFile>$key</AssemblyOriginatorKeyFile>")
$text = $regexOut.Replace($text,
{
param($m)
$newPath = [System.IO.Path]::Combine($m.Groups["value"].Value, "Signed")
return "<OutputPath>$newPath</OutputPath>"
})
$text = $regexDoc.Replace($text,
{
param($m)
$docOld = $m.Groups["value"].Value
$docDir = [System.IO.Path]::GetDirectoryName($docOld)
$docFile = [System.IO.Path]::GetFileName($docOld)
$newPath = [System.IO.Path]::Combine([System.IO.Path]::Combine($docDir, "Signed"), $docFile)
return "<DocumentationFile>$newPath</DocumentationFile>"
})
[System.IO.File]::WriteAllText($dst, $text)
# changes directory to the specified location, while allowing
# to return back to the original location with Pop-Location
Push-Location $dstDir
$dstFileName = [System.IO.Path]::GetFileName($dst)
& "$msb" "$dstFileName"
Pop-Location
Remove-Item $dst