Skip to Content
PowerShell 烹饪书,第 4 版
book

PowerShell 烹饪书,第 4 版

by Lee Holmes
May 2025
Intermediate to advanced
1002 pages
12h 51m
Chinese
O'Reilly Media, Inc.
Content preview from PowerShell 烹饪书,第 4 版

第 19 章 Visual Studio 代码

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

19.0 引言

虽然 文本模式的 PowerShell 在效率和自动化方面非常出色,但它的用户界面却没什么可说的。就控制台应用程序而言(尤其是在 Windows 终端中),PowerShell 确实令人惊叹。但与传统的集成开发环境相比,PowerShell 的用户体验还有待提高。

所有这些都是pwsh.exe作为控制台应用程序的简单副作用。这些问题会影响每个操作系统上的每个控制台应用程序,而且很可能会一直影响下去。

,控制台应用程序的致命缺陷还在于它们不完全支持 Unicode 标准:即大多数国际语言表示其字母的方式。虽然 Windows 控制台支持一些基本的非英语字符(如重音符号字母),但它几乎不支持其他字符。Windows 终端应用程序大大改进了这一点,但其覆盖范围仍不全面。

事实证明,这对全球的管理员来说都是一个相当大的问题!由于直接在命令行键入国际字符非常困难,许多国家的管理员不得不在记事本中编写脚本以获得完全的 Unicode 支持,然后使用 PowerShell 运行脚本,即使命令最终只有一行。

PowerShell 通过与 VisualStudioCode 的全面集成解决了这些问题。

Visual Studio Code 为 PowerShell 提供了现代应用程序所期望的用户界面,支持完整的 Unicode 输入和多标签会话,并为交互式调试提供了良好的体验。

从概念上讲,Visual Studio Code 由两个主要组件组成(如图 19-1 所示):

编辑

编辑器是 Visual Studio Code 的顶部窗格,面向多行脚本编辑和创建。它提供行号和语法高亮显示,并支持出色的调试体验。

脚本窗格的一个独特之处在于它支持选择性执行:只运行你高亮显示的内容,而不是你正在处理的整个脚本。这使得编写脚本变得轻而易举。当你开始编写脚本时,你可以交互式地尝试执行命令,直到正确为止。一旦它们达到预期效果,你就可以将它们保留下来,继续编写脚本。正如您对 PowerShell 控制台 shell 所期待的那样,脚本窗格中的脚本编辑支持命令、参数、路径等的制表符补全。

控制台面板

控制台面板位于应用程序的底部,是您在 Visual Studio Code 中进行大部分交互会话的地方。与 PowerShell 控制台中的命令提示符一样,控制台面板也支持选项卡补全

与 Windows 终端一样,如果发现命令太长,可以按下 Shift-Enter 键,启用当前命令的多行编辑。

如果想让 Visual Studio Code 看起来像 PowerShell 集成脚本环境,只需选择 "视图"→"命令调板",然后搜索 "PowerShell":启用 ISE 模式"。

除这些功能外,Visual Studio Code 还提供广泛的自定义、脚本和远程支持。

wps4 1402
图 19-1. Visual Studio 代码

19.1 调试脚本

问题

您 希望通过比*-PsBreakpoint cmdlets 更友好的界面使用 PowerShell 的调试命令。

解决方案

使用 Visual ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

《SQL 概论》,第 4 版

《SQL 概论》,第 4 版

Kevin Kline, Regina O. Obe, Leo S. Hsu
《MySQL 烹饪书》第 4 版

《MySQL 烹饪书》第 4 版

Sveta Smirnova, Alkin Tezuysal

Publisher Resources

ISBN: 9798341657984