Powershell 脚本在ISE中工作,但不在Visual Studio代码中工作,脚本或VS代码有问题吗?
我目前正在运行我为练习而编写的以下脚本,因为我正在尝试提高我的powershell技能,我想从一些基础知识开始,以防我在慢慢拼凑知识、计算圆和其他形状/形式以稍微处理函数时遗漏一些东西Powershell 脚本在ISE中工作,但不在Visual Studio代码中工作,脚本或VS代码有问题吗?,powershell,visual-studio-code,powershell-ise,Powershell,Visual Studio Code,Powershell Ise,我目前正在运行我为练习而编写的以下脚本,因为我正在尝试提高我的powershell技能,我想从一些基础知识开始,以防我在慢慢拼凑知识、计算圆和其他形状/形式以稍微处理函数时遗漏一些东西 function calculate-circle{ $pi = 3.14 [float]$radius = read-host "What is the radius?" $surface = $radius*$radius*$pi write-host "The surface area of a cir
function calculate-circle{
$pi = 3.14
[float]$radius = read-host "What is the radius?"
$surface = $radius*$radius*$pi
write-host "The surface area of a circle with radius $radius is $surface"
}
在Powershell ISE中,它执行时没有任何缺陷,我可以输入半径并进行计算
在VS代码中,在突出显示整个脚本并使用“在活动终端中运行所选文本”的热键运行它之后,我得到了以下内容
我不明白的是,这是我的代码的问题还是VS代码中的Powershell的一些怪癖?我真的很喜欢VS代码的一些功能,所以我有点生气。非常感谢 使用命令调色板中的
终端:在活动终端
中运行所选文本命令,也可以从终端
菜单中访问运行所选文本
,分别提交和执行所选行,这不适用于多行代码段,如函数定义
相反,使用PowerShell扩展附带的PowerShell:Run Selection
命令,默认情况下,该命令绑定到热键F8,就像在ISE中一样;您还可以使用运行选择
命令从选择的上下文菜单访问它
PS C:\> function calculate-circle{
Missing closing '}' in statement block or type definition.
At line:0 char:0
PS C:\> $mypi = 3.14
PS C:\> [float]$radius = read-host "What is the radius?"
What is the radius?:
PS C:\> $surface = $radius*$radius*$mypi
PS C:\> write-host "The surface area of a circle with radius $radius is $surface"
The surface area of a circle with radius 0 is 0
PS C:\> }
At line:1 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.