记录在windows下安装Dapr报错问题

windows系统安装Dapr时,使用给的命令:powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex",运行后报错。
记录在windows下安装Dapr报错问题

发现来源是github,直接去看github上找源文件就好了。https://github.com/dapr/cli/blob/master/install/install.ps1
在本地创建一个txt文件,把网页内容复制到txt文件中并重命名成install.ps1。
记录在windows下安装Dapr报错问题
记住这个路径,并将powershell中的路径进行替换powershell -Command "iwr -useb D:\EXE\install.ps1 | iex"。
将https换成本地路径。

安装完成后,在系统变量中加入文件所在的路径。
记录在windows下安装Dapr报错问题

重新启动powershell,输入dapr,如图说明成功安装了。

记录在windows下安装Dapr报错问题

文件内容贴在这里了。

------------------------------------------------------------

Copyright (c) Microsoft Corporation and Dapr Contributors.

Licensed under the MIT License.

------------------------------------------------------------

param (
[string]$Version,
[string]$DaprRoot = "c:\dapr",
[string]$DaprReleaseJsonUrl = "",
[scriptblock]$CustomAssetFactory = $null
)

Write-Output ""
$ErrorActionPreference = ‘stop‘

Escape space of DaprRoot path

$DaprRoot = $DaprRoot -replace ‘ ‘, ‘` ‘

Constants

$DaprCliFileName = "dapr.exe"
$DaprCliFilePath = "${DaprRoot}${DaprCliFileName}"

GitHub Org and repo hosting Dapr CLI

$GitHubOrg = "dapr"
$GitHubRepo = "cli"

Set Github request authentication for basic authentication.

if ($Env:GITHUB_USER) {
$basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN));
$githubHeader = @{"Authorization" = "Basic $basicAuth" }
}
else {
$githubHeader = @{}
}

if ((Get-ExecutionPolicy) -gt ‘RemoteSigned‘ -or (Get-ExecutionPolicy) -eq ‘ByPass‘) {
Write-Output "PowerShell requires an execution policy of ‘RemoteSigned‘."
Write-Output "To make this change please run:"
Write-Output "‘Set-ExecutionPolicy RemoteSigned -scope CurrentUser‘"
break
}

Change security protocol to support TLS 1.2 / 1.1 / 1.0 - old powershell uses TLS 1.0 as a default protocol

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

Check if Dapr CLI is installed.

if (Test-Path $DaprCliFilePath -PathType Leaf) {
Write-Warning "Dapr is detected - $DaprCliFilePath"
Invoke-Expression "$DaprCliFilePath --version"
Write-Output "Reinstalling Dapr..."
}
else {
Write-Output "Installing Dapr..."
}

Create Dapr Directory

Write-Output "Creating $DaprRoot directory"
New-Item -ErrorAction Ignore -Path $DaprRoot -ItemType "directory"
if (!(Test-Path $DaprRoot -PathType Container)) {
Write-Warning "Please visit https://docs.dapr.io/getting-started/install-dapr-cli/ for instructions on how to install without admin rights."
throw "Cannot create $DaprRoot"
}

Get the list of release from GitHub

$releaseJsonUrl = $DaprReleaseJsonUrl
if (!$releaseJsonUrl) {
$releaseJsonUrl = "https://api.github.com/repos/${GitHubOrg}/${GitHubRepo}/releases"
}

$releases = Invoke-RestMethod -Headers $githubHeader -Uri $releaseJsonUrl -Method Get
if ($releases.Count -eq 0) {
throw "No releases from github.com/dapr/cli repo"
}

get latest or specified version info from releases

function GetVersionInfo {
param (
[string]$Version,
$Releases
)
# Filter windows binary and download archive
if (!$Version) {
$release = $Releases | Where-Object { $.tag_name -notlike "rc" } | Select-Object -First 1
}
else {
$release = $Releases | Where-Object { $
.tag_name -eq "v$Version" } | Select-Object -First 1
}

return $release

}

get info about windows asset from release

function GetWindowsAsset {
param (
$Release
)
if ($CustomAssetFactory) {
Write-Output "CustomAssetFactory dectected, try to invoke it"
return $CustomAssetFactory.Invoke($Release)
}
else {
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows_amd64.zip" }
if (!$windowsAsset) {
throw "Cannot find the windows Dapr CLI binary"
}
[hashtable]$return = @{}
$return.url = $windowsAsset.url
$return.name = $windowsAsset.name
return $return
}`
}

$release = GetVersionInfo -Version $Version -Releases $releases
if (!$release) {
throw "Cannot find the specified Dapr CLI binary version"
}
$asset = GetWindowsAsset -Release $release
$zipFileUrl = $asset.url
$assetName = $asset.name

$zipFilePath = $DaprRoot + "" + $assetName
Write-Output "Downloading $zipFileUrl ..."

$githubHeader.Accept = "application/octet-stream"
$oldProgressPreference = $progressPreference;
$progressPreference = ‘SilentlyContinue‘;
Invoke-WebRequest -Headers $githubHeader -Uri $zipFileUrl -OutFile $zipFilePath
$progressPreference = $oldProgressPreference;
if (!(Test-Path $zipFilePath -PathType Leaf)) {
throw "Failed to download Dapr Cli binary - $zipFilePath"
}

Extract Dapr CLI to $DaprRoot

Write-Output "Extracting $zipFilePath..."
Microsoft.Powershell.Archive\Expand-Archive -Force -Path $zipFilePath -DestinationPath $DaprRoot
if (!(Test-Path $DaprCliFilePath -PathType Leaf)) {
throw "Failed to download Dapr Cli archieve - $zipFilePath"
}

Check the Dapr CLI version

Invoke-Expression "$DaprCliFilePath --version"

Clean up zipfile

Write-Output "Clean up $zipFilePath..."
Remove-Item $zipFilePath -Force

Add DaprRoot directory to User Path environment variable

Write-Output "Try to add $DaprRoot to User Path Environment variable..."
$UserPathEnvironmentVar = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPathEnvironmentVar -like ‘dapr‘) {
Write-Output "Skipping to add $DaprRoot to User Path - $UserPathEnvironmentVar"
}
else {
[System.Environment]::SetEnvironmentVariable("PATH", $UserPathEnvironmentVar + ";$DaprRoot", "User")
$UserPathEnvironmentVar = [Environment]::GetEnvironmentVariable("PATH", "User")
Write-Output "Added $DaprRoot to User Path - $UserPathEnvironmentVar"
}

Write-Output "rnDapr CLI is installed successfully."
Write-Output "To get started with Dapr, please visit https://docs.dapr.io/getting-started/ ."
Write-Output "Ensure that Docker Desktop is set to Linux containers mode when you run Dapr in self hosted mode."

记录在windows下安装Dapr报错问题

上一篇:WPF xaml中写代码


下一篇:MutationObserver API