powershell - 当我需要启用 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 命令来执行此操作?
解决方案
有多个直接从下载文件调用文件的示例。例如:在官方文档页面(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
推荐阅读
- azure - 在具有外部访问权限的 Azure VM 中预配 SQL Always on
- javascript - 使用 MySQL 表达 JS REST API
- cypher - 我可以将 ANSI SQL 用于 AgensGraph 中的图形数据吗?
- python - 具有重复的有序节点和/或边的 Python Networkx 或 igraph DAG
- c - putchar(ch + 1) 没有立即放入 char
- html - 如何在 div 标签 I 中居中我的文本,为什么它在单词 an 和极端之间有一个空格?
- excel - 查找包含 ICD-10 代码的数据行的疯狂嵌套 Excel(或 VBA)语句
- python - 分组方式,最小最大,平均时间
- c++ - c++ 将打印格式从整数 2255 更改为 $xx.xx
- javascript - Javascript 对象:如何使键的值成为另一个键(不是键的值)?