Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何排除错误[术语';pwsh.exe';不被识别为cmdlet、函数、脚本文件或可操作程序的名称]?_Powershell_.net Core_Powershell V6.0 - Fatal编程技术网

Powershell 如何排除错误[术语';pwsh.exe';不被识别为cmdlet、函数、脚本文件或可操作程序的名称]?

Powershell 如何排除错误[术语';pwsh.exe';不被识别为cmdlet、函数、脚本文件或可操作程序的名称]?,powershell,.net-core,powershell-v6.0,Powershell,.net Core,Powershell V6.0,在Azure DevOps上创建新管道以为.NET项目设置CI时,我设置了以下PowerShell脚本以自动化.NET核心设置 以下是脚本: $ErrorActionPreference="Stop" $ProgressPreference="SilentlyContinue" # $LocalDotnet is the path to the locally-installed SDK to ensure the # correct version

在Azure DevOps上创建新管道以为.NET项目设置CI时,我设置了以下PowerShell脚本以自动化.NET核心设置

以下是脚本:

$ErrorActionPreference="Stop"
$ProgressPreference="SilentlyContinue"

# $LocalDotnet is the path to the locally-installed SDK to ensure the
#   correct version of the tools are executed.
$LocalDotnet=""
# $InstallDir and $CliVersion variables can come from options to the
#   script.
$InstallDir = "./cli-tools"
$CliVersion = "1.0.1"

# Test the path provided by $InstallDir to confirm it exists. If it
#   does, it's removed. This is not strictly required, but it's a
#   good way to reset the environment.
if (Test-Path $InstallDir)
{
    rm -Recurse $InstallDir
}
New-Item -Type "directory" -Path $InstallDir

Write-Host "Downloading the CLI installer..."

# Use the Invoke-WebRequest PowerShell cmdlet to obtain the
#   installation script and save it into the installation directory.
Invoke-WebRequest `
    -Uri "https://dot.net/v1/dotnet-install.ps1" `
    -OutFile "$InstallDir/dotnet-install.ps1"

Write-Host "Installing the CLI requested version ($CliVersion) ..."

# Install the SDK of the version specified in $CliVersion into the
#   specified location ($InstallDir).
& $InstallDir/dotnet-install.ps1 -Version $CliVersion `
    -InstallDir $InstallDir

Write-Host "Downloading and installation of the SDK is complete."

# $LocalDotnet holds the path to dotnet.exe for future use by the
#   script.
$LocalDotnet = "$InstallDir/dotnet"
尝试运行生成时,出现以下错误:


我已经在谷歌上搜索过有同样问题的人以及如何解决。但是我还没有找到太多的信息。Azure DevOps论坛也无济于事。

如上面的评论所述,您所要做的就是在运行代理的计算机上安装适当版本的PowerShell。例如然后必须确保设置了环境变量
path
。此变量应指向具有PowerShell Core的目录

窗户 只需使用Windows安装程序(PowerShell Git存储库中的
.msi
文件)安装PowerShell Core即可。在这种情况下,
path
环境变量将自动设置或展开,以便在该变量下有指向目录的路径,路径为
pwsh.exe

Linux 安装您的发行版支持的PowerShell Core。确保在
~/.bashrc
文件中有
path
变量,并且
path
包含指向PowerShell Core目录的路径


注意:如果Azure代理已经在运行,您必须重新启动它,以便它看到
路径中的更改。因此,在Windows上,如果以交互方式运行,只需重新启动代理,如果作为服务运行,则重新启动服务。在Linux上,您可以按照指南更新传递给代理的环境变量


我知道您已经将脚本配置为PowerShell核心脚本,但为了完整性,我添加了以下内容:如果您在Azure管道中使用PowerShell任务,默认情况下不会为其设置PowerShell的核心版本。要将任务作为PowerShell核心脚本运行,请将其添加到任务的YAML代码中:
pwsh:true
。否则,如果您仍在使用旧的图形界面,请选中任务“高级”标题下的“使用PowerShell Core”复选框。

我使用的是dotnet Core cli 2.1.500版,顺便说一句,这是基本版--它不在当前环境中
$env:path
的任何目录中。如果您想使用powershell core的beta版,您可能需要将其与dotnet core一起安装。powershell.exe是Windows的一部分,pwsh.exe不是(目前)。感谢@Simply Ged,我在使用powershell处理Windows环境方面不是很有经验,因此我发现的许多问题对我来说都是新问题。。除此之外,即使花了几天时间在谷歌上寻求帮助,还是没能取得任何进展。为了让它正常工作,我必须在安装powershell后重新启动计算机。