首页 > 解决方案 > 当我需要启用 Tls1.2 时,如何从下载的脚本安装 dotnet core?

问题描述

我有一个 CI/CD 脚本,它使用脚本 ( https://dot.net/v1/dotnet-install.ps1 ) 安装 dotnet 核心。我们下载(并缓存)脚本,然后想使用 powershell 直接从脚本中调用它

powershell -NoLogo -NonInteractive -NoProfile -ExecutionPolicy unrestricted -File "%MYDIR%\dotnet-install.ps1" -Version 2.1.806

但是,在 CI/CD 机器上,这会失败:

dotnet-install: Downloading link: https://dotnetcli.[snip]/dotnet-sdk-2.1.806-win-x86.zip
dotnet-install: Cannot download: https://dotnetcli.[snip]/dotnet-sdk-2.1.806-win-x86.zip
dotnet-install: Downloading legacy link: https://dotnetcli.[snip]/dotnet-dev-win-x86.2.1.806.zip
dotnet-install: Cannot download: https://dotnetcli.[snip]/dotnet-dev-win-x86.2.1.806.zip
Could not find/download: ".NET Core SDK" with version = 2.1.806

事实证明,这失败了,因为我们无法建立安全连接,需要启用 Tls1.2

如何修改我的 powershell 命令来执行此操作?

标签: powershell.net-coretls1.2

解决方案


有多个直接从下载文件调用文件的示例。例如:在官方文档页面(https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script):

powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) <additional install-script args>"

但是,我无法从本地下载/缓存的文件中找到任何直接执行此操作的示例。如果您需要使用 TLS 1.2 调用的本地文件,请尝试以下操作:

powershell -NoLogo -NonInteractive -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; . '%MYDIR%\dotnet-install.ps1'" -Version 2.1.806

推荐阅读