-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathupdate-nuget-frameworks.ps1
117 lines (97 loc) · 3.92 KB
/
update-nuget-frameworks.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
param (
[String] $VersionTag = "6.8.0.117"
)
$root = Resolve-Path "$PSScriptRoot/.."
$source = "$root/artifacts/tmp/NuGet.Client"
if (Test-Path $source) {
Remove-Item -Recurse -Force $source
}
git clone --depth 1 --branch $VersionTag https://github.com/NuGet/NuGet.Client.git $source
if (0 -ne $LASTEXITCODE) {
throw "Cloning failed."
}
$commit = git -C $source log -1 --pretty=format:"%h"
if (0 -ne $LASTEXITCODE) {
throw "Getting commit failed."
}
$destination = "$root/src/Microsoft.TestPlatform.ObjectModel/Nuget.Frameworks/"
$frameworksPath = "$source/src/NuGet.Core/NuGet.Frameworks"
$frameworkItems = @(
"DefaultFrameworkMappings.cs"
"DefaultFrameworkNameProvider.cs"
"DefaultPortableFrameworkMappings.cs"
"DefaultCompatibilityProvider.cs"
"CompatibilityProvider.cs"
"FrameworkConstants.cs"
"FrameworkException.cs"
"FrameworkNameProvider.cs"
"FrameworkRange.cs"
"FrameworkReducer.cs"
"FrameworkNameHelpers.cs",
"FrameworkSpecificMapping.cs"
"FallbackFramework.cs"
"FrameworkExpander.cs"
"CompatibilityCacheKey.cs"
"def/IFrameworkCompatibilityListProvider.cs"
"def/IFrameworkCompatibilityProvider.cs"
"def/IFrameworkMappings.cs"
"def/IFrameworkNameProvider.cs"
"def/IFrameworkSpecific.cs"
"def/IPortableFrameworkMappings.cs"
"NuGetFramework.cs"
"NuGetFrameworkFactory.cs"
"comparers/NuGetFrameworkFullComparer.cs"
"comparers/NuGetFrameworkNameComparer.cs"
"comparers/CompatibilityMappingComparer.cs"
"comparers/FrameworkRangeComparer.cs"
"comparers/NuGetFrameworkSorter.cs"
"comparers/FrameworkPrecedenceSorter.cs"
"NuGetFrameworkUtility.cs"
"OneWayCompatibilityMappingEntry.cs"
) | ForEach-Object { "$frameworksPath/$_" }
$extraItems = @(
".editorconfig"
"build/Shared/HashCodeCombiner.cs"
"build/Shared/NoAllocEnumerateExtensions.cs"
"build/Shared/StringBuilderPool.cs"
"build/Shared/SimplePool.cs"
) | ForEach-Object { "$source/$_" }
if ((Test-Path $destination)) {
Remove-Item $destination -Force -Recurse
}
New-Item -ItemType Directory $destination -ErrorAction Ignore | Out-Null
foreach ($item in $frameworkItems + $extraItems) {
if (-not (Test-Path $item)) {
throw "File not found $item"
}
$content = Get-Content $item
$name = (Get-Item $item).Name
$path = "$destination/$name"
# some types are directly in Nuget namespace, and if we would suffix
# .Clone, then Nuget.Frameworks.Clone is no longer autometicaly using
# Nuget.Clone, and we would have to add more usings into the files.
$finalContent = $content `
-replace 'public(.*)(class|interface)', 'internal$1$2' `
-replace 'namespace NuGet', 'namespace NuGetClone' `
-replace 'using NuGet', 'using NuGetClone' `
-replace 'NuGet.Frameworks.NuGetFramework', 'NuGetClone.Frameworks.NuGetFramework'
if ($name -eq ".editorconfig") {
$finalContent += @"
[*.{cs,vb}]
dotnet_diagnostic.IDE0001.severity = none
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.IDE1006.severity = none
"@
}
$finalContent | Set-Content -Path $path -Encoding utf8NoBOM
}
@"
This directory contains code that is copied from https://github.com/NuGet/NuGet.Client/tree/dev/src/NuGet.Core/NuGet.Frameworks, with the namespaces changed
and class visibility changed. This is done to ensure we are providing the same functionality as Nuget.Frameworks, without depending on the package explicitly.
The files in this folder are coming from tag $VersionTag, on commit $commit.
To update this code, run the script in: $($PSCommandPath -replace [regex]::Escape($root)) , with -VersionTag <theDesiredVersion>.
"@ | Set-Content "$destination/README.md"
$tpnPath = "$root/src/package/ThirdPartyNotices.txt"
$tpn = Get-Content $tpnPath -Raw
$tpn = $tpn -replace "Nuget.Client version.*\(", "Nuget.Client version $versionTag \("
$tpn | Set-Content -Path $tpnPath -Encoding utf8NoBOM -NoNewline