-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathpatch-msbuild.ps1
More file actions
73 lines (57 loc) · 2.25 KB
/
patch-msbuild.ps1
File metadata and controls
73 lines (57 loc) · 2.25 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
# THIS IS JUST TEMPORARY
# We are waiting on the release of VS 2020 P5
Param (
[string] $MSBuild = "$env:MSBUILD_EXE"
)
$ErrorActionPreference = "Stop"
$msbuildRoot = Split-Path -Parent $MSBuild
$files = @{
'System.Text.Json' = '5.0.0.0';
'System.Text.Encodings.Web' = '5.0.0.0';
'System.Threading.Tasks.Extensions' = '4.2.0.1';
}
$urls = @{
'https://globalcdn.nuget.org/packages/system.text.json.5.0.0.nupkg' = 'lib\net461\System.Text.Json.dll';
'https://globalcdn.nuget.org/packages/system.text.encodings.web.5.0.0.nupkg' = 'lib\netstandard2.0\System.Text.Encodings.Web.dll';
'https://globalcdn.nuget.org/packages/system.threading.tasks.extensions.4.5.4.nupkg' = 'lib\netstandard2.0\System.Threading.Tasks.Extensions.dll';
}
# backup
Write-Host "Backing up files..."
foreach ($file in $files.GetEnumerator()) {
$p = Join-Path $msbuildRoot "$($file.Key).dll"
if (!(Test-Path $p-old)) {
Move-Item $p $p-old
}
}
# replace
foreach ($url in $urls.GetEnumerator()) {
$nupkg = Split-Path -Leaf $url.Key
$dst = Join-Path $env:TEMP $nupkg
$extract = "$dst-out"
$dll = Split-Path -Leaf $url.Value
$src = Join-Path $extract $url.Value
$dst = Join-Path $msbuildRoot $dll
Write-Host "Replacing file '$dll'..."
# clean
Remove-Item -Force -Recurse -ErrorAction Ignore $dst
Remove-Item -Force -Recurse -ErrorAction Ignore $extract
# download and extract
Invoke-WebRequest -Uri $url.Key -OutFile $dst
Expand-Archive -Path $dst -DestinationPath $extract
# copy
Copy-Item -Path $src -Destination $dst
}
# update config
$config = [xml](Get-Content "$MSBuild.config")
foreach ($file in $files.GetEnumerator()) {
Write-Host "Updating config for file '$($file.Key).dll'..."
$v = $file.Value
$rootXpath = "/configuration/runtime/*[local-name()='assemblyBinding']/*[local-name()='dependentAssembly' and *[local-name()='assemblyIdentity' and @name='$($file.Key)']]/*[local-name()='bindingRedirect']"
$oldVersionXpath = "$rootXpath/@oldVersion"
$node = $config.SelectNodes($oldVersionXpath)[0]
$node.Value = "0.0.0.0-$v"
$newVersionXpath = "$rootXpath/@newVersion"
$node = $config.SelectNodes($newVersionXpath)[0]
$node.Value = $v
}
$config.Save("$MSBuild.config")