@@ -179,53 +179,20 @@ private static BuildScript DownloadDotNetVersion(Autobuilder builder, string pat
179179
180180 if ( builder . Actions . IsWindows ( ) )
181181 {
182- var psScript = @"param([string]$Version, [string]$InstallDir)
183182
184- add-type @""
185- using System.Net;
186- using System.Security.Cryptography.X509Certificates;
187- public class TrustAllCertsPolicy : ICertificatePolicy
188- {
189- public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
190- {
191- return true;
192- }
193- }
194- ""@
195- $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
196- [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
197- [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
198- $Script = Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'
199-
200- $arguments = @{
201- Channel = 'release'
202- Version = $Version
203- InstallDir = $InstallDir
204- }
205-
206- $ScriptBlock = [scriptblock]::create("".{$($Script)} $(&{$args} @arguments)"")
183+ var psCommand = $ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version { version } -InstallDir { path } ";
207184
208- Invoke-Command -ScriptBlock $ScriptBlock" ;
209- var psScriptFile = builder . Actions . PathCombine ( builder . Options . RootDirectory , "install-dotnet.ps1" ) ;
210- builder . Actions . WriteAllText ( psScriptFile , psScript ) ;
211-
212- var install = new CommandBuilder ( builder . Actions ) .
213- RunCommand ( "powershell" ) .
185+ BuildScript GetInstall ( string pwsh ) =>
186+ new CommandBuilder ( builder . Actions ) .
187+ RunCommand ( pwsh ) .
214188 Argument ( "-NoProfile" ) .
215189 Argument ( "-ExecutionPolicy" ) .
216190 Argument ( "unrestricted" ) .
217- Argument ( "-file" ) .
218- Argument ( psScriptFile ) .
219- Argument ( "-Version" ) .
220- Argument ( version ) .
221- Argument ( "-InstallDir" ) .
222- Argument ( path ) ;
223-
224- var removeScript = new CommandBuilder ( builder . Actions ) .
225- RunCommand ( "del" ) .
226- Argument ( psScriptFile ) ;
191+ Argument ( "-Command" ) .
192+ Argument ( "\" " + psCommand + "\" " ) .
193+ Script ;
227194
228- return install . Script & BuildScript . Try ( removeScript . Script ) ;
195+ return GetInstall ( "pwsh" ) | GetInstall ( "powershell" ) ;
229196 }
230197 else
231198 {
0 commit comments