forked from NuGet/NuGet.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuget-debug-helpers.ps1
265 lines (223 loc) · 11.5 KB
/
nuget-debug-helpers.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
$NuGetClientRoot= Resolve-Path $(Join-Path $PSScriptRoot "..\")
$Configuration = "Debug"
$NETFramework = "net472"
$NETStandard = "netstandard2.0"
$NETCoreApp = "netcoreapp5.0"
<#
Auto bootstraps NuGet for debugging the targets. This includes both restore and pack and is the recommended way to test things :)
.EXAMPLE
This runs restore on the NuGet.sln. The args here are equivalent to the args you would pass to an MSBuild invocation.
C:\PS> Invoke-NuGetCustom /t:restore NuGet.sln
#>
Function Invoke-NuGetCustom()
{
$packDllPath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks.Pack\bin\$Configuration\$NETFramework\NuGet.Build.Tasks.Pack.dll"
$packTargetsPath = Join-Path $NuGetClientRoot "src\NuGet.Core\NuGet.Build.Tasks.Pack\NuGet.Build.Tasks.Pack.targets"
$restoreDllPath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks\bin\$Configuration\$NETFramework\NuGet.Build.Tasks.dll"
$nugetRestoreTargetsPath = Join-Path $NuGetClientRoot "src\NuGet.Core\NuGet.Build.Tasks\NuGet.targets"
$consoleExePath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks.Console\bin\$Configuration\$NETFramework\NuGet.Build.Tasks.Console.exe"
Write-Host "msbuild /p:NuGetRestoreTargets=$nugetRestoreTargetsPath /p:RestoreTaskAssemblyFile=$restoreDllPath /p:NuGetBuildTasksPackTargets=$packTargetsPath /p:NuGetConsoleProcessFileName=$consoleExePath /p:ImportNuGetBuildTasksPackTargetsFromSdk=true /p:NuGetPackTaskAssemblyFile=$packDllPath $($args[0..$args.Count])"
& msbuild /p:NuGetRestoreTargets=$nugetRestoreTargetsPath /p:RestoreTaskAssemblyFile=$restoreDllPath /p:NuGetBuildTasksPackTargets=$packTargetsPath /p:NuGetConsoleProcessFileName=$consoleExePath /p:ImportNuGetBuildTasksPackTargetsFromSdk=true /p:NuGetPackTaskAssemblyFile=$packDllPath $args[0..$args.Count]
}
<#
Auto bootstraps NuGet for debugging the restore targets only (this doesn't include the pack targets!)
.EXAMPLE
This runs restore on the NuGet.sln. The args here are equivalent to the args you would pass to an MSBuild invocation.
C:\PS> Invoke-NuGetCustom /t:restore NuGet.sln
#>
Function Invoke-NuGetRestoreCustom()
{
$restoreDllPath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks\bin\$Configuration\$NETFramework\NuGet.Build.Tasks.dll"
$nugetRestoreTargetsPath = Join-Path $NuGetClientRoot "src\NuGet.Core\NuGet.Build.Tasks\NuGet.targets"
$consoleExePath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks.Console\bin\$Configuration\$NETFramework\NuGet.Build.Console.exe"
Write-Host "msbuild /p:NuGetRestoreTargets=$nugetRestoreTargetsPath /p:RestoreTaskAssemblyFile=$restoreDllPath /p:NuGetConsoleProcessFileName=$consoleExePath $($args[0..$args.Count])"
& msbuild /p:NuGetRestoreTargets=$nugetRestoreTargetsPath /p:RestoreTaskAssemblyFile=$restoreDllPath /p:NuGetConsoleProcessFileName=$consoleExePath $args[0..$args.Count]
}
<#
Auto bootstraps NuGet for debugging the pack targets only (this doesn't include the restore targets!)
.EXAMPLE
This runs pack on the NuGet.sln. The args here are equivalent to the args you would pass to an MSBuild invocation.
C:\PS> Invoke-NuGetPackCustom /t:pack NuGet.sln
#>
Function Invoke-NuGetPackCustom()
{
$packDllPath = Join-Path $NuGetClientRoot "artifacts\NuGet.Build.Tasks.Pack\bin\$Configuration\$NETFramework\NuGet.Build.Tasks.Pack.dll"
$packTargetsPath = Join-Path $NuGetClientRoot "src\NuGet.Core\NuGet.Build.Tasks.Pack\NuGet.Build.Tasks.Pack.targets"
Write-Host "msbuild /p:NuGetBuildTasksPackTargets=$packTargetsPath /p:ImportNuGetBuildTasksPackTargetsFromSdk=true /p:NuGetPackTaskAssemblyFile=$packDllPath $($args[0..$args.Count])"
& msbuild /p:NuGetBuildTasksPackTargets=$packTargetsPath /p:ImportNuGetBuildTasksPackTargetsFromSdk=true /p:NuGetPackTaskAssemblyFile=$packDllPath $args[0..$args.Count]
}
<#
Patches the necessary NuGet assemblies in dotnet.exe.
.EXAMPLE
C:\PS> Add-NuGetToCLI -sdkLocation D:\dotnet\sdk\5.0.0-preview4\
#>
Function Add-NuGetToCLI {
param
(
[string]$sdkLocation,
[switch]$createSdkLocation
)
if ( (-Not $createSdkLocation) -And (-Not (Test-Path $sdkLocation)))
{
Write-Error "The SDK path $sdkLocation does not exist!"
return;
}
if($createSdkLocation)
{
if(-Not (Test-Path $sdkLocation))
{
New-Item $sdkLocation -ItemType Directory
}
}
$sdk_path = $sdkLocation
$nugetXplatArtifactsPath = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'NuGet.CommandLine.XPlat', 'bin', $Configuration, $NETCoreApp)
$nugetBuildTasks = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'NuGet.Build.Tasks', 'bin', $Configuration, $NETCoreApp, 'NuGet.Build.Tasks.dll')
$nugetBuildTasksConsole = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'NuGet.Build.Tasks.Console', 'bin', $Configuration, $NETCoreApp, 'NuGet.Build.Tasks.Console.dll')
$nugetTargets = [System.IO.Path]::Combine($NuGetClientRoot, 'src', 'NuGet.Core', 'NuGet.Build.Tasks', 'NuGet.targets')
$nugetExTargets = [System.IO.Path]::Combine($NuGetClientRoot, 'src', 'NuGet.Core', 'NuGet.Build.Tasks', 'NuGet.RestoreEx.targets')
$ilmergedCorePackTasks = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'NuGet.Build.Tasks.Pack', 'bin', $Configuration, $NETStandard, "ilmerge", "NuGet.Build.Tasks.Pack.dll")
$ilmergedFrameworkPackTasks = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'NuGet.Build.Tasks.Pack', 'bin', $Configuration, $NETFramework, "ilmerge", "NuGet.Build.Tasks.Pack.dll")
$nugetPackTargets = [System.IO.Path]::Combine($NuGetClientRoot, 'src', 'NuGet.Core', 'NuGet.Build.Tasks.Pack', 'NuGet.Build.Tasks.Pack.targets')
$msbuildSdkResolverTasks = [System.IO.Path]::Combine($NuGetClientRoot, 'artifacts', 'Microsoft.Build.NuGetSdkResolver', 'bin', $Configuration, $NETCoreApp, 'Microsoft.Build.NuGetSdkResolver.dll')
if (-Not (Test-Path $nugetXplatArtifactsPath)) {
Write-Error "$nugetXplatArtifactsPath not found!"
return;
}
if (-Not (Test-Path $nugetBuildTasks)) {
Write-Error "$nugetBuildTasks not found!"
return;
}
if (-Not (Test-Path $nugetBuildTasksConsole)) {
Write-Error "$nugetBuildTasksConsole not found!"
return;
}
if (-Not (Test-Path $nugetTargets)) {
Write-Error "$nugetTargets not found!"
return;
}
if (-Not (Test-Path $nugetExTargets)) {
Write-Error "$nugetExTargets not found!"
return;
}
if (-Not (Test-Path $ilmergedCorePackTasks)) {
Write-Error "$ilmergedCorePackTasks not found!"
return;
}
if (-Not (Test-Path $ilmergedFrameworkPackTasks)) {
Write-Error "$ilmergedFrameworkPackTasks not found!"
return;
}
if (-Not (Test-Path $nugetPackTargets)) {
Write-Error "$nugetPackTargets not found!"
return;
}
if (-Not (Test-Path $msbuildSdkResolverTasks)) {
Write-Error "$msbuildSdkResolverTasks not found!"
return;
}
Write-Host
Write-Host "Source commandline path - $nugetXplatArtifactsPath"
Write-Host "Destination sdk path - $sdk_path"
Write-Host
## Copy the xplat artifacts
Get-ChildItem $nugetXplatArtifactsPath -Filter NuGet*.dll |
Foreach-Object {
$new_position = "$($sdk_path)\$($_.BaseName )$($_.Extension )"
Write-Host "Moving to - $($new_position)"
Copy-Item $_.FullName $new_position
}
## Copy the restore artifacts
$buildTasksDest = "$($sdk_path)\NuGet.Build.Tasks.dll"
Write-Host "Moving to - $($buildTasksDest)"
Copy-Item $nugetBuildTasks $buildTasksDest
$buildTasksConsoleDest = "$($sdk_path)\NuGet.Build.Tasks.Console.dll"
Write-Host "Moving to - $($buildTasksConsoleDest)"
Copy-Item $nugetBuildTasksConsole $buildTasksConsoleDest
$nugetTargetsDest = "$($sdk_path)\NuGet.targets"
Write-Host "Moving to - $($nugetTargetsDest)"
Copy-Item $nugetTargets $nugetTargetsDest
$nugetRestoreExTargetsDest = "$($sdk_path)\NuGet.RestoreEx.targets"
Write-Host "Moving to - $($nugetRestoreExTargetsDest)"
Copy-Item $nugetExTargets $nugetRestoreExTargetsDest
## Copy the pack SDK.
$packSdkPath = "$($sdk_path)\Sdks\NuGet.Build.Tasks.Pack"
$nugetPackTargetsCrossTargetingDest = "$($packSdkPath)\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets"
Write-Host "Moving to - $($nugetPackTargetsCrossTargetingDest)"
Copy-Item $nugetPackTargets $nugetPackTargetsCrossTargetingDest
$nugetPackTargetsDest = "$($packSdkPath)\build\NuGet.Build.Tasks.Pack.targets"
Write-Host "Moving to - $($nugetPackTargetsDest)"
Copy-Item $nugetPackTargets $nugetPackTargetsDest
$packTasksCoreDest = "$($packSdkPath)\CoreCLR\NuGet.Build.Tasks.Pack.dll"
Write-Host "Moving to - $($packTasksCoreDest)"
Copy-Item $ilmergedCorePackTasks $packTasksCoreDest
$packTasksFrameworkDest = "$($packSdkPath)\Desktop\NuGet.Build.Tasks.Pack.dll"
Write-Host "Moving to - $($packTasksFrameworkDest)"
Copy-Item $ilmergedFrameworkPackTasks $packTasksFrameworkDest
## Copy the resolver
$msbuildSdkResolverTasksDest = "$($sdk_path)\Microsoft.Build.NuGetSdkResolver.dll"
Write-Host "Moving to - $($msbuildSdkResolverTasksDest)"
Copy-Item $msbuildSdkResolverTasks $msbuildSdkResolverTasksDest
}
<#
Downgrades the NuGet extension in all Visual Studio instances on the machine.
Assumes the VSIXInstaller.exe is on the path.
#>
Function DowngradeNuGetVsix()
{
& VSIXInstaller.exe /d:NuGet.72c5d240-f742-48d4-a0f1-7016671e405b
}
<#
Installs the NuGet extension build in the local repo.
#>
Function InstallCustomNuGetVsix()
{
& VSIXInstaller.exe $(Join-Path $NuGetClientRoot "artifacts\VS15\NuGet.Tools.vsix" )
}
<#
Enable Visual Studio telemetry file logging.
#>
Function EnableVisualStudioTelemetryFileLogging()
{
$command = "reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\Telemetry\Channels /v fileLogger /t reg_dword /f /d 00000001"
Invoke-Expression $command
}
<#
Disable Visual Studio telemetry file logging
#>
Function DisableVisualStudioTelemetryFileLogging()
{
$command = "reg delete HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\Telemetry\Channels /v fileLogger /f"
Invoke-Expression $command
}
<#
Isolate the restore output folders. When run, this redirects all NuGet folders and caches to the directory passed in as $RootDirectory.
The root folder *must* exist.
.EXAMPLE
C:\PS> IsolateRestore -sdkLocation D:\source\NuGet.Client
.EXAMPLE
C:\PS> IsolateRestore -sdkLocation .
#>
Function IsolateRestore {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$RootDirectory
)
$RootDirectory = Resolve-Path $RootDirectory
Write-Host "The root directory is $RootDirectory"
$gpf = Join-Path $RootDirectory -ChildPath "gpf"
$httpCache = Join-Path $RootDirectory -ChildPath "httpCache"
$pluginLogs = Join-Path $RootDirectory -ChildPath "plugin-logs"
Write-Host "Setting the global packages folder to $gpf"
$env:NUGET_PACKAGES=$gpf
Write-Host "Setting the http cache to $httpCache"
$env:NUGET_HTTP_CACHE_PATH=$httpCache
Write-Host "Enabling the plugins loggings"
$Env:NUGET_PLUGIN_ENABLE_LOG='true'
Write-Host "Setting the plugin log directory to $pluginLogs"
$Env:NUGET_PLUGIN_LOG_DIRECTORY_PATH=$pluginLogs
Write-Host "Creating the plugin logs path."
New-Item -ItemType directory -Path $pluginLogs
# https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders
# https://github.com/NuGet/Home/wiki/Plugin-Diagnostic-Logging
}