如何:使用 Visual Studio Code 共同作業How-to: Collaborate using Visual Studio Code

準備好在 VS Code 中使用 Live Share 進行共同作業了嗎?Ready to get collaborating with Live Share in VS Code? 如果是這樣,您來對地方了!If so, you're in the right spot! 在本文中,我們將逐步引導您了解如何使用適用於 Visual Studio Code 的 Visual Studio Live Share 擴充的特定功能。In this article, we'll walk you through how to use some of the specific features in the Visual Studio Live Share extension for Visual Studio Code.

請注意,這裡所描述的所有共同作業活動,都會涉及單一共同作業工作階段主持人,以及一或多個來賓Note that all collaboration activities described here involve a single collaboration session host and one or more guests. 主持人是啟動共同作業工作階段的人員,而來賓是加入的任何人。The host is the person that started the collaboration session and anyone that joins is a guest.

在尋找簡易摘要嗎?請改為參閱共用加入快速入門。Looking for an abridged summary? Check out the share or join quickstarts instead.

提示

您知道您可以「加入自己的共同作業工作階段」** 嗎?Did you know you can join your own collaboration session? 這讓您可以自行試用 Live Share,或是啟動 Visual Studio 或 VS Code 的執行個體,並從遠端連線到該執行個體!This allows you to try Live Share on your own or to spin up an instance of Visual Studio or VS Code and connect to it remotely! 您甚至可以在這兩個執行個體使用相同的身分識別。You can even use the same identity in both instances. 趕緊去瞧一瞧!Check it out!

安裝Installation

開始之前,您必須確定已安裝符合 Live Share 核心需求的 Visual Studio Code 版本。Before you begin, you'll need to be sure you've got a version of Visual Studio Code installed that meets Live Share's core requirements. 您需要在下列平台上執行的 Visual Studio Code (1.22.0 或更高版本)You'll need Visual Studio Code (1.22.0 or higher) running on:

  • Windows:7、8.1 或10Windows: 7, 8.1, or 10

  • macOS:僅限塞拉里昂(10.12)和更新版本。macOS: Sierra (10.12) and above only.

  • Linux:64位 Ubuntu Desktop 16.04 +、Fedora Workstation 27 +、CentOS 7Linux: 64-bit Ubuntu Desktop 16.04+, Fedora Workstation 27+, CentOS 7

之後就能輕鬆下載並安裝 Visual Studio Live Share 延伸模組:After that, downloading and installing the Visual Studio Live Share extension is a breeze:

  1. 安裝Visual Studio CodeInstall Visual Studio Code
  2. 從 marketplace下載並安裝 Visual Studio Live Share 延伸模組。Download and install the Visual Studio Live Share extension from the marketplace.
  3. 重新載入 Visual Studio CodeReload Visual Studio Code
  4. 等候相依性完成下載和安裝 (查看狀態列)。Wait for dependencies to download and install (see status bar).
    完成安裝Finishing install
  5. Linux:如果您看到有關安裝遺失程式庫的通知:Linux: If you see a notification about installing missing libraries:
    1. 按一下通知中的 [安裝]。Click "Install" in the notification.
    2. 收到提示時,輸入您的系統管理員 (sudo) 密碼。Enter your admin (sudo) password when prompted.
    3. 於完成時重新啟動 VS Code。Restart VS Code when done.

下載並使用 Visual Studio Live Share 即表示您同意授權條款隱私權聲明By downloading and using Visual Studio Live Share, you agree to the license terms and privacy statement. 如果您遇到問題,請參閱疑難排解See troubleshooting if you run into problems.

下載Download

Linux 安裝步驟Linux install steps

Linux 環境彼此之間很容易具有高度差異,其為數眾多的桌面環境和散發套件,很可能會使作業變得複雜。Linux is a highly variable environment and with the sheer number of desktop environments and distributions can be complicated to get working. 不過,如果您維持使用 Ubuntu Desktop (16.04+)、Fedora Workstation (27+) 或 CentOS 7,且僅使用 VS Code 的官方散發套件,整個流程應該不會有任何變數。If you stick to supported versions of Ubuntu Desktop (16.04+) or Fedora Workstation (27+), CentOS 7 and only use official distributions of VS Code, you should find the process straightforward. 不過,在使用非標準設定或下游散發套件的情況下,您便有可能會遇到問題。However, in the event that you are using a non-standard configuration or downstream distribution, you may or may not run into some hiccups. 請參閱 Linux 安裝詳細資料以取得詳細資訊。See Linux installation details for more information.

安裝 Linux 必要條件Install Linux prerequisites

某些 Linux 散發套件並沒有 Live Share 運作所需的程式庫。Some distributions of Linux are missing libraries Live Share needs to function. 根據預設,Live Share 會嘗試偵測並為您安裝 Linux 必要條件。By default, Live Share attempts to detect and install Linux prerequisites for you. 當 Live Share 遇到可能源自遺失程式庫的問題時,便會向您顯示快顯通知並要求安裝它們的權限。You'll see a toast notification when Live Share encounters a problem that can originate from missing libraries asking you for permission to install them.

顯示 Linux 必要條件遺失之訊息的快顯通知

當您按一下 [安裝] 時,將會出現終端機視窗,且您必須在其中輸入系統管理員 (sudo) 密碼以繼續。When you click "Install", a terminal window will appear where you'll need to enter your admin (sudo) password to continue. 當此作業成功完成之後,請重新啟動 Visual Studio Code,一切便能就緒!Assuming it completes successfully, restart Visual Studio Code you should be all set! 您也應該查看 依散發套件分類的提示,以查看其他提示和現有的因應措施。You may also want to check out tips by distribution for other hints and workarounds if any exist.

如果您看見指令碼不支援散發套件的訊息,請參閱 適用於社群支援散發套件的提示 以取得社群已和我們分享的相關資訊。If you see a message indicating the script does not support your distribution, see tips for community supported distributions for information the community has shared with us.

如果您不想讓 VS Code 為您執行命令,您也可以從終端機視窗執行下列命令,以隨時手動選擇重新執行此指令碼的最新版本:If you prefer not to have VS Code run the command for you, you can also opt to re-run the very latest version of this script at any time manually by running the following command from a Terminal window:

wget -O ~/vsls-reqs https://aka.ms/vsls-linux-prereq-script && chmod +x ~/vsls-reqs && ~/vsls-reqs

Linux 瀏覽器整合Linux browser integration

Visual Studio Live Share 通常不需要額外安裝步驟以在 Linux 上啟用瀏覽器整合。Visual Studio Live Share typically does not require additional installation steps to enable browser integration on Linux.

雖然此情況並不常見,但在某些散發套件上系統可能會通知您需要系統管理員 (sudo) 密碼才能完成安裝程序。While uncommon, on certain distributions you may be notified that your admin (sudo) password is required to complete the installation process. 系統將會顯示終端機視窗,向您告知瀏覽器啟動器的安裝位置。A terminal window will appear telling you where the browser launcher will be installed. 請在收到提示時直接輸入您的密碼,然後在安裝完成時按 Enter 以關閉終端機視窗。Simply enter your password when prompted and press enter once the installation completes to close the terminal window.

您可以在 這裡 深入了解此要求背後的原因,以及 Live Share 放置檔案的位置。You can read more about why this is required and where Live Share places files here. 請注意,即使您無法順利使瀏覽器整合運作,您仍然可以 手動加入共同作業工作階段Note even if you are unable to get browser integration working you can still join collaboration sessions manually.

登入Sign in

若要進行共同作業,您需要登入 Visual Studio Live Share,以便使所有人知道您的身分。In order to collaborate, you'll need to sign into Visual Studio Live Share so everyone knows who you are. 這只是安全性措施,並會將您加入任何行銷或其他研究活動。This is purely a security measure and does not opt you into any marketing or other research activities. 您可以使用 Microsoft 個人帳戶 (例如 @outlook.com)、Microsoft 支援的公司或學校帳戶 (AAD),或是 GitHub 帳戶。You can sign in using a Microsoft personal account (e.g. @outlook.com), Microsoft-backed work or school account (AAD), or a GitHub account. 登入很簡單。Signing in is easy.

按一下[Live Share] 狀態列專案,或按Ctrl + shift + p/Cmd + shift + p並選取 [Live Share:使用瀏覽器登入] 命令。Click on the "Live Share" status bar item or press Ctrl+Shift+P / Cmd+Shift+P and select the "Live Share: Sign In With Browser" command.

VS Code [登入] 按鈕

系統將會顯示通知,要求您使用網頁瀏覽器登入。A notification will appear asking you to sign in using your web browser. 按一下 [啟動登入] 將會開啟瀏覽器,以供您用來完成登入程序。Clicking "launch sign in" will open a browser for you to use to complete the sign-in process. 完成後,請直接關閉瀏覽器。Simply close the browser when done.

使用網頁瀏覽器要求您登入的快顯通知

Linux 使用者: 如果您使用舊版的 Live Share (0.3.295 或更低版本),系統可能會提示您輸入使用者程式碼。Linux users: You may be prompted to enter a user code if you are using an older version of Live Share (v0.3.295 or below). 將延伸模組更新為最新版本,或在登入後按一下 [遇到問題了嗎?]Update to the latest version of the extension or click the "Having trouble?" 連結以查看程式碼。link after sign in to see the code. 如需詳細資訊,請參閱下文。See below for details.

Advanced tip:liveshare.account liveshare.accountProvider 如果您有多個可用帳戶的快取認證,和設定可讓您選取應該使用哪一個帳戶來進行自動登入。Advanced tip: The liveshare.account and liveshare.accountProvider settings enable you to select which account should be used for automatic sign-in in case you have cached credentials for multiple accounts available. 例如,假設您在進行 2 個專案,並想要使用不同的身分認證登入。For example, imagine you work on 2 projects with which you want to sign in with different identities. 在 VSCode 工作區設定中,您可以在每個專案目錄中將 liveshare.account 設定設為不同的電子郵件地址,以確保每個專案目錄都使用正確的帳戶自動登入。In your VSCode workspace settings, you could set the liveshare.account setting to different email addresses in each project directory to ensure they each automatically sign-in with the correct account. 如果您針對多個提供者使用相同的電子郵件地址,liveshare.accountProvider 設定無法設為 "microsoft""github"The liveshare.accountProvider setting could be set to either "microsoft" or "github" in case you use the same email address with multiple providers.

在您於瀏覽器中完成登入程序後,如果 Visual Studio Code 並沒有偵測到您的登入,請參閱使用使用者程式碼登入If Visual Studio Code is not picking up your sign in after you complete the sign-in process in the browser, see sign in using a user code. 否則,請參閱疑難排解以取得其他提示。Otherwise, check out troubleshooting for more tips.

使用使用者程式碼登入Sign in using a user code

如果您遇到 VS Code 沒有偵測到已完成登入的問題,則可以改為輸入「使用者程式碼」。If you are running into problems with VS Code not picking up a completed sign in, you can enter a "user code" instead.

  1. Ctrl + shift + P/Cmd + shift + P ,然後執行「Live Share:使用使用者程式碼登入」命令。Press Ctrl+Shift+P / Cmd+Shift+P and run the "Live Share: Sign in with user code" command.

  2. 系統應該會顯示瀏覽器,以供您用來完成登入程序。A browser should appear for you use to complete the sign-in process.

    注意

    如果未自動出現瀏覽器,請在瀏覽器中開啟這個位置 (英文) 並登入。If a browser does not appear automatically, open this location in a browser and sign in.

  3. 完成之後,請按一下 [有任何問題嗎?Once you are done, click "Having trouble? 按一下這裡以取得使用者程式碼指示] 以查看使用者程式碼。Click here for user code directions" to see the user code.

    瀏覽器中使用者程式碼的圖片

  4. 複製使用者程式碼。Copy the user code.

  5. 最後,將使用者程式碼貼到執行命令後所出現的輸入欄位中,然後按 Enter 以完成登入程序。Finally, paste the user code into the input field that appeared when you ran the command and press enter to complete the sign-in process.

    使用者程式碼輸入欄位的圖片

使用 Live Share viewletUsing the Live Share viewlet

安裝 Visual Studio Live Share 之後,系統會將自訂索引標籤新增至 VS Code 活動列上。After installing Visual Studio Live Share, a custom tab will be added to the VS Code activity bar. 在此索引標籤中,您可以存取所有的 Live Share 功能以進行共同作業。In this tab, you can access all Live Share functions to collaborate. 此外,當您共用或加入共同作業工作階段時,[總管] 索引標籤中也會出現檢視,以供您存取所有這些功能。Additionally, when you share or join a collaboration session, a view will also appear in the Explorer tab for you to access all these functions as well.

Live Share custom tab Live Share explorer view

透過這些檢視,您便可以查看參與者在共用程式碼中所在的位置、按一下參與者以追蹤他們、聚焦在參與者身上、存取共用的伺服器和終端機等。With these views, you can see a participant's location in the shared code, click on a participant to follow them, focus participants, access shared servers and terminals, and more.

使用範圍命令功能表Using the scoped command menu

此外,所有的 Visual Studio Live Share 功能都可以從 Visual Studio Code 的 [命令選擇區] 中取得,您可以按 Ctrl+Shift+P / Cmd+Shift+P 或 F1 來存取 [命令選擇區]。Additionally, all Visual Studio Live Share functions are available from the Visual Studio Code "Command Palette" that can be accessed by pressing Ctrl+Shift+P / Cmd+Shift+P or F1. 您可以輸入 "live share" 來取得命令的完整清單。You can find a complete list of commands by typing "live share".

由於此清單可能很長,您應該運用狀態列所提供的範圍命令功能表。Since this list can get long, you may find it easier to take advantage of a scoped command menu available from the status bar. 按一下狀態列上的登入/工作階段狀態圖示,將會立即顯示可供您使用之命令的內容相關清單。Clicking on the sign in / session state icon in the status bar will immediately bring up a contextualized list of commands that are available for you to use.

VS Code 工作階段狀態圖示

共用專案Share a project

下載並安裝 Visual Studio Live Share 之後,請遵循這些步驟來啟動共同作業工作階段,並邀請同事與您合作。After downloading and installing Visual Studio Live Share, follow these steps to start a collaboration session and invite a colleague to work with you.

  1. 登入Sign in

    安裝 Live Share 擴充,重新載入,並等待相依性完成安裝之後,您應該登入以便使其他共同作業者知道您的身分。After installing the Live Share extension, reloading, and waiting for dependencies to finish installing, you'll want to sign in to let other collaborators know who you are. 請參閱登入,以取得詳細資料。See sign in for more details.

  2. 開啟資料夾Open a folder

    使用您的一般工作流程來開啟您希望與來賓共用的資料夾、專案或方案。Use your normal workflow to open a folder, project, or solution you would like to share with your guests.

  3. [選擇性] 更新隱藏或排除的檔案[Optional] Update hidden or excluded files

    根據預設,Live Share 會向來賓隱藏您共用資料夾中 .gitignore 檔案所參考的任何檔案/資料夾。By default, Live Share hides any files/folders referenced in .gitignore files in your shared folders from guests. 隱藏檔案可防止該檔案在來賓的檔案樹狀目錄中顯示。Hiding a file prevents it from appearing in the guest's file tree. [排除]**** 檔案會套用更嚴格的規則,以防止 Live Share 在您前往定義,或在偵錯中或「受到跟隨」時進入檔案等情況下,為來賓開啟該檔案。Excluding a file applies a stricter rule that will prevent Live Share from opening it for the guest in situations like go to a definition or if you step into the file while debugging or being "followed". 如果您希望隱藏/排除不同的檔案,您可以使用這些設定將 .vsls.json 檔案新增至您的專案。If you want to hide/exclude different files, a .vsls.json file can be added to your project with these settings. 請參閱控制檔案存取權和可見性以取得詳細資料。See controlling file access and visibility for details.

  4. 開始共同作業工作階段Start a collaboration session

    現在,直接按一下[Live Share] 狀態列專案,或按Ctrl + shift + p/Cmd + shift + p並選取 [Live Share:啟動共同作業會話(共用)]。Now, simply click the "Live Share" status bar item or hit Ctrl+Shift+P / Cmd+Shift+P and select "Live Share: Start a collaboration session (Share)".

    [共用] 按鈕

    注意

    桌面防火牆軟體可能會要求您允許 Live Share 代理程式在您第一次共用時開啟連接埠。You may be asked by your desktop firewall software to allow the Live Share agent to open a port the first time you share. 這完全是選擇性的,但是當您與一起工作的人員位於相同網路時,可提供安全的「直接模式」來改善效能。Accepting this is entirely optional but enables a secured "direct mode" to improve performance when the person you are working with is on the same network as you are. 請參閱變更連線模式以取得詳細資料。See changing the connection mode for details.

    邀請連結將會自動複製到剪貼簿。An invite link will be automatically copied to your clipboard. 在瀏覽器中開啟時,此連結可讓其他人加入新的共同作業工作階段,並與他們共用這些資料夾的內容。When opened in a browser, this link allows others to join a new collaboration session that shares contents of these folders with them.

    您也會看見 [Live Share] 狀態列的項目轉換,以代表工作階段狀態。You will also see the "Live Share" status bar item transition to represent the session state. 如需按鈕的外觀,請參閱下面的工作階段狀態資訊。See session state information below for what this looks like.

    請注意,如果您要在啟動共用之後再次取得邀請連結,您可以按一下工作階段狀態列圖示並選取 [邀請其他人 (複製連結)] 來再次存取它。Note that if you need to get the invite link again after you've started sharing, you access it again by clicking on the session state status bar icon and select "Invite Others (Copy Link)".

  5. [選擇性] 啟用唯讀模式[Optional] Enable read-only mode

    一旦您啟動共同作業工作階段,您可以將工作階段設定為唯讀,以防止來賓對正在共用的程式碼進行編輯。Once you start your collaboration session, you can set the session to be read-only to prevent guests from making edits to the code being shared.

    共用之後,您會收到通知指出邀請連結已複製到剪貼簿。After sharing, you will get a notification that the invite link has been copied to your clipboard. 您隨即可以選取選項來將工作階段設為唯讀。You can then select the option to make the session read-only.

    VS Code 唯讀模式

  6. 將連結傳送給某人Send someone the link

    透過電子郵件、Slack、Skype 等將連結傳送給您希望邀請的人員。Send the link over e-mail, Slack, Skype, etc. to those you want to invite. 請注意,考慮到 Live Share 工作階段所能為來賓提供的存取層級,您應該只與您信任的人共用,並考量共用這些內容的影響。Note that, given the level of access Live Share sessions can provide to guests, you should only share with people you trust and think through the implications of what you are sharing.

    安全性秘訣: 想要瞭解某些 Live Share 功能的安全性含意嗎?Security Tip: Want to understand the security implications of some of Live Share's features? 請參閱安全性一文。Check out the security article.

    如果您邀請的來賓有問題,「快速入門:加入您的第一個會話」一文會提供一些關於以來賓身分啟動並執行的詳細資訊。If the guest you invited has questions, the "Quickstart: Join your first session" article provides some more information on getting up and running as a guest.

  7. [選擇性] 核准來賓[Optional] Approve the guest

    根據預設,來賓會自動加入您的共同作業工作階段,當他們準備好要與您共同作業時,您會收到通知。By default, guests will automatically join your collaboration session and you'll be notified when they're ready to work with you. 雖然此通知提供您將他們從工作階段移除的選項,但您也可以選擇改為要加入的任何人都需要明確地「核准」。While this notification gives you the option to remove them from the session, you can also opt to instead require an explicit "approval" for anyone joining.

    若要啟用這個功能,請直接將下列內容新增至 settings.json:To enable this feature, simply add the following to settings.json:

      "liveshare.guestApprovalRequired": true
    

    一旦您開啟此設定,系統會通知您進行核准,來賓才能加入。Once you have this setting turned on, a notification will prompt you to approve the guest before they can join.

    Visual Studio Code 加入核准要求

    如需邀請安全性考量的其他詳細資料,請參閱邀請和加入存取權See invitations and join access for additional details on invitation security considerations.

就這麼容易!That's it!!

停止共同作業工作階段Stop the collaboration session

身為主持人,您可以隨時完全停止共用並結束共同作業工作階段,方法是開啟 [總管] 中的 [Live Share] 檢視或 [Live Share] 自訂索引標籤,然後選取 [停止共同作業工作階段] 圖示。As a host, you can stop sharing completely and end the collaboration session at any time by opening the Live Share view in the Explorer or in the Live Share custom tab and selecting the "Stop collaboration session" icon.

停止共同作業工作階段

系統會通知所有來賓工作階段已經結束。All guests will be notified that the session has ended. 工作階段結束之後,來賓將不再能夠存取內容,且系統會清除任何暫存檔。Once the session has ended, guests will no longer be able to access the content and any temp files are automatically cleaned up.

有共用的問題嗎?Having issues with sharing? 請參閱疑難排解Check out troubleshooting.

加入共同作業工作階段Join a collaboration session

下載並安裝 Visual Studio Live Share 之後,來賓只需要幾個步驟就能加入主持人主持的共同作業工作階段。After downloading and installing Visual Studio Live Share, guests only need to take a couple of steps to join a hosted collaboration session. 有兩種方式可以加入:透過瀏覽器手動There are two ways to join: via the browser and manually.

安全性秘訣: 當來賓加入共同作業會話時,請務必瞭解,主機可能會限制您對特定檔案或功能的存取。Security Tip: As a guest joining a collaboration session, it's important to understand that hosts may restrict your access to certain files or features. 想要了解 Live Share 功能和設定的一些安全性影響嗎?Want to understand the security implications of some of Live Share's features and settings? 請參閱安全性一文。Check out the security article.

透過瀏覽器加入Join via the browser

加入共同作業工作階段最簡單的方式,是在網頁瀏覽器中直接開啟邀請連結。The easiest way to join a collaboration session is to simply open the invite link in a web browser. 當您遵循此流程時,預期的情況如下。Here's what you can expect when you follow this flow.

  1. 登入Sign in

    安裝 Live Share 擴充,重新載入,並等待相依性完成安裝之後,您應該登入以便使其他共同作業者知道您的身分。After installing the Live Share extension, reloading, and waiting for dependencies to finish installing, you'll want to sign in to let other collaborators know who you are. 請參閱登入,以取得詳細資料。See sign in for more details.

  2. 按一下邀請連結/在您的瀏覽器中開啟邀請Click on the invite link / open the invite in your browser

    現在,請在瀏覽器中開啟 (或重新開啟) 邀請連結。Now, simply open (or re-open) the invite link in a browser.

    注意:如果您尚未安裝 Live Share 擴充功能,您會看到延伸模組 marketplace 的連結。Note: If you have not yet installed the Live Share extension, you'll be presented with links to the extension marketplace. 安裝擴充並重新啟動您的工具,然後重試。Install the extension and restart your tool and retry.

    您應該會收到通知,指出瀏覽器想要啟動提供 Live Share 的工具。You should be notified that the browser wants to launch a Live Share enabled tool. 如果您讓其啟動所選的工具,則在啟動後您將連線至共同作業工作階段。If you let it launch your selected tool, you'll be connected to the collaboration session once it starts.

    加入頁面

    如果主持人已離線,則會改為在此時收到通知。If the host is offline, you'll be notified at this point instead. 您可以連絡主持人,並要求再次共用。You can then contact the host and ask them to share again.

    注意

    請務必在安裝 Visual Studio Live Share 擴充後至少啟動工具一次並允許安裝完成,再開啟/重新開啟邀請頁面。Be sure you've started the tool at least once after installing the Visual Studio Live Share extension and allowed the installation to finish before opening/re-opening the invite page. 仍然遇到問題嗎?Still having trouble? 請參閱手動加入See join manually.

  3. 共同作業Collaborate

    完成了!That's it! 稍後會建立連線,您就可以開始共同作業。In a few moments you'll be connected and you can start collaborating.

    您將會看到 [Live Share] 按鈕發生轉換以表示「工作階段狀態」。You will see the "Live Share" button transition to convey a "Session State". 如需按鈕的外觀,請參閱下面的工作階段狀態資訊。See session state information below for what this looks like.

    完成加入之後,系統會自動帶您到主持人目前在編輯的檔案。You'll then be automatically taken to the file the host is currently editing once the join is complete.

手動加入Join manually

您也可以手動加入,而不使用網頁瀏覽器。此方式在下列情況可能很有用:您想要使用的工具已經在執行、您想要使用其他工具而非平常使用的工具,或您可能因某些原因而無法取得邀請連結。You can also manually join without using a web browser which can be useful in situations where the tool you want to use is already running, you want to use a different tool than you usually do, or if you are having trouble with getting invite links to work for some reason. 流程很簡單:The process is easy:

  1. 登入Sign in

    安裝 Live Share 擴充,重新載入,並等待相依性完成安裝之後,您應該登入以便使其他共同作業者知道您的身分。After installing the Live Share extension, reloading, and waiting for dependencies to finish installing, you'll want to sign in to let other collaborators know who you are. 請參閱登入,以取得詳細資料。See sign in for more details.

  2. 使用加入命令Use the join command

    開啟 VS Code 活動列中的 [Live Share] 自訂索引標籤,然後選取 [加入共同作業工作階段] 圖示或重試。Open the Live Share custom tab in the VS Code activity bar, and select the "Join collaboration session..." icon or entry.

    加入 viewlet 圖示

  3. 貼上邀請連結Paste the invite link

    貼上您收到的邀請 URL 並按 Enter 以確認。Paste in the invite URL you were sent and hit enter to confirm.

  4. 共同作業!Collaborate!

    完成了!That's it! 您應該很快就會連線到共同作業工作階段。You should be connected to the collaboration session momentarily.

    您將會看到 [Live Share] 按鈕發生轉換以表示「工作階段狀態」。You will see the "Live Share" button transition to convey a "Session State". 如需按鈕的外觀,請參閱下面的工作階段狀態資訊。See session state information below for what this looks like.

    完成加入之後,系統會自動帶您到主持人目前在編輯的檔案。You'll then be automatically taken to the file the host is currently editing once the join is complete.

離開共同作業工作階段Leave the collaboration session

身為來賓,您可以直接關閉 VS Code 視窗來離開共同作業工作階段,而不會結束其他人的作業。As a guest, you can leave the collaboration session without ending it for others by simply closing the VS Code window. 如果您想讓視窗保持開啟,則可以開啟 Live Share [總管] 檢視或 [Live Share] 自訂索引標籤,並選取 [離開共同作業工作階段] 圖示。If you'd prefer to keep the window open, you can open the Live Share Explorer view or the Live Share custom tab and select the "Leave collaboration session" icon.

離開工作階段圖示

系統會自動清除任何暫存檔,所以您無須採取進一步動作。Any temp files are automatically cleaned up so no further action is needed.

有加入的問題嗎?Having issues with joining? 請參閱疑難排解Check out troubleshooting.

共同編輯Co-editing

來賓加入共同作業工作階段之後,所有共同作業者都能立刻即時地看到其他人所編輯和選取的項目。Once a guest has joined a collaboration session, all collaborators will immediately be able to see each other's edits and selections in real-time. 您只需要從 [檔案總管] 中挑選檔案並開始編輯。All you need to do is pick a file from the file explorer and start editing. 當您在編輯時,主持人和來賓都能查看,並且能親自參與,使逐一查看變得簡單,而且很快就能找出解決方案。Both hosts and guests will see edits as you make them and can contribute themselves making it easy iterate and rapidly nail to down solutions.

注意

加入唯讀共同作業工作階段會防止來賓對檔案進行編輯。Joining a read-only collaboration session prevents guests from being able to make edits to files. 主持人可以在共用時啟用唯讀模式A host can enable read-only mode when they share. 身為來賓,您可以查看您的工作階段狀態,以分辨您是否已加入唯讀工作階段。As a guest, you can tell if you have joined a read-only session by looking at your session state.

顯示共同編輯的螢幕擷取畫面

注意

對於特定語言,共同編輯有一些限制。Co-editing has limitations for certain languages. 如需依語言列出功能的狀態,請參閱平台支援See platform support for the state of features by language.

除了游標和編輯之外,在相同檔案中的參與者也能看到您所選取的項目。Beyond cursors and edits, selections you make are also visible to all participants in that same file. 這可以讓您輕鬆反白顯示問題的可能位置或傳達想法。This makes it easy to highlight where problems might exist or convey ideas.

顯示反白顯示的螢幕擷取畫面

更棒的是,您和其他參與者可以瀏覽至共用專案中的任何檔案。Better yet, you and other participants can navigate to any file in the shared project. 你們可以一起或獨立地編輯,這表示您可以流暢地在進行調查、做出小型調整,以及採取完全共同作業編輯之間進行切換。You can either edit together or independently meaning you can seamlessly switch between investigation, making small tweaks and full collaborative editing.

編輯的結果會於儲存時保留在主持人的機器上,因此當您完成編輯時,不需要互相同步、推送或傳送檔案。The resulting edits are persisted on the host's machine on save so there is no need to synchronize, push, or send files around once you're done editing. 您所做的編輯都會「直接保留」。The edits are "just there."

安全性秘訣: 假設所有參與者都可以獨立地流覽和編輯檔案,身為主機,您可能會想要限制來賓能夠透過 .vsls.json 檔案在您的專案中存取的檔案。Security Tip: Given all participants can independently navigate and edit files, as a host, you may want to restrict which files guests are able to access in your project via a .vsls.json file. 身為來賓,請務必了解到因為這些設定,您可能不會看到特定檔案。As a guest, it is also important to realize you may not see certain files as a result of these settings. 請參閱控制檔案存取權和可見性以取得詳細資料。See controlling file access and visibility for details.

變更參與者旗標行為Changing participant flag behaviors

根據預設,當暫留在參與者的指標上時,或當參與者編輯、反白顯示或移動其指標時,Visual Studio Live Share 會自動在其指標旁邊顯示「旗標」。By default, Visual Studio Live Share automatically displays a "flag" next to a participant's cursor on hover, or when they edit, highlight, or move their cursor. 在某些情況下,您可能會想要變更此行為。In some cases, you may prefer to change this behavior.

請直接編輯 settings.json ([檔案] > [喜好設定] > [設定]),新增下列其中一行,然後重新啟動 VS Code:Simply edit settings.json (File > Preferences > Settings), add one of the following lines, and then restart VS Code:

設定Setting 行為Behavior
"liveshare.nameTagVisibility":"Never" 只有當您暫留在指標上時旗標才可見。The flag is only visible when you hover over the cursor.
"liveshare.nameTagVisibility":"Activity" 此為預設值。This is the default. 暫留在指標上時,或當參與者編輯、反白顯示或移動其指標時,旗標才為可見。The flag is visible on hover or if the participant edits, highlights, or moves their cursor.
"liveshare.nameTagVisibility":"Always" 旗標一律為可見。The flag is always visible.

追蹤中Following

您有時需要說明橫跨多個檔案或程式碼中多個位置的問題和設計。Sometimes you need to explain a problem or design that spans multiple files or locations in code. 在這些情況下,暫時追蹤同事在專案中的動作可能會很有用。In these situations, it can be useful to temporarily follow a colleague as they move throughout the project. 因此,當您加入共同作業工作階段時,您會自動「追蹤」主持人。For this reason, when you join a collaboration session you will automatically "follow" the host. 在追蹤某人時,您的編輯器會與他們目前開啟的檔案和捲動位置保持同步。When following someone, your editor will stay in sync with their currently open file and scroll position.

注意

根據預設,Live Share 也會共用位於已共用資料夾外的檔案。By default, Live Share shares opened files external to the shared folder as well. 如果您想要停用此功能,請在 settings.json 中將 liveshare.shareExternalFiles Live Share 更新為 falseIf you want to disable this feature, update liveshare.shareExternalFiles Live Share to false in settings.json.

若要開始遵循參與者(做為主機或來賓),請在 [Live Share Explorer] 或 [自訂] 索引標籤的 [參與者] 清單中,按一下其名稱。其名稱旁邊的圓形將會填入,表示您正在關注這些專案。To start following a participant (as either a host or guest), click on their name in the participants' list in the Live Share Explorer view or custom tab. The circle next to their name will fill in to indicate you are following them.

VS Code 從 viewlet 追蹤

或者,您可以按一下編輯器群組右上角的圖釘圖示,或按 Ctrl+Alt+F / Cmd+Alt+FAlternatively, you can click the pin icon in the upper right of the editor group or press Ctrl+Alt+F / Cmd+Alt+F.

VS Code 圖釘

注意

如果有多個其他人位於共同作業工作階段中,系統將會詢問您要追蹤哪一個參與者。If more than one other person is in the collaboration session, you'll be asked to select the participant you want to follow.

顯示共同作業者清單的螢幕擷取畫面

由於追蹤是繫結至編輯者群組,您可以使用分割檢視 (或是格線配置!) 來建立會追蹤某個參與者的群組,以及另一個不會追蹤該參與者的群組。Since following is tied to an editor group, you can use split view (or grid layout!) to have a group that is following a participant and a group that is not. 這可讓您在被動地追蹤某個人的情況下,同時個別處理其他工作。This allows you to passively follow someone while also working on something independently. 在選取編輯者群組時,您可以從參與者清單中選取某個參與者,來讓該群組追蹤他們。With an editor group selected, you can select a participant in the participants list to have that group follow them.

VS Code 分割檢視中的圖釘

為了方便切換離開「追蹤模式」並開始自行編輯,如果發生下列情況,您就會自動停止追蹤:To make it easy to switch out of "follow mode" and start editing on your own, you'll automatically stop following if any of these occur:

  1. 您開始編輯目前的作用中檔案You start editing the currently active file
  2. 您開啟其他檔案You open a different file
  3. 您關閉目前的作用中檔案You close the currently active file

此外,您可以再次按一下圖釘圖示,或按 Ctrl+Alt+F / Cmd+Alt+F來明確地停止追蹤某人。Additionally, you can explicitly stop following someone by clicking the pin icon again or hitting Ctrl+Alt+F / Cmd+Alt+F.

列出參與者Listing participants

查看共同作業會話中誰的快速方法,就是查看 [Live Share Explorer] 視圖或 [自訂] 索引標籤中的 [參與者] 清單。這些 views 會顯示您會話中的所有參與者。A quick way to see who is in the collaboration session is to look at the participants list in the Live Share Explorer view or custom tab. The views will show all the participants in your session.

顯示使用者狀態列圖示的螢幕擷取畫面

按一下清單中的任何參與者,將會在您的作用中編輯器群組中追蹤他們。Clicking on any participant in this list will follow them in your active editor group.

或者,您也可以按Ctrl + shift + P/Cmd + shift + P並選取 [Live Share:列出參與者] 命令,或按一下狀態列專案,顯示會話中的參與者數目。Alternatively, you can hit Ctrl+Shift+P / Cmd+Shift+P and select the "Live Share: List Participants" command or click on the status bar item that shows the number of participants in your session.

顯示使用者狀態列圖示的螢幕擷取畫面

系統將會顯示工作階段中所有參與者的清單。A list of all participants in the session will then appear. 和按一下圖釘圖示不同,就算工作階段中除了您以外只有另一個人員,此清單仍然會顯示,讓您隨時都可以快速地查看其他人所在的位置。Unlike clicking the pin icon, this list appears even if there is only one other person in the session with you so you can always quickly see where someone else is located. 為了方便起見,和圖釘圖示一樣,您接著可以從清單中選擇其中一個參與者來追蹤他們。For convenience purposes, like the pin icon, you can then pick one of the participants from the list to follow them. 如果您想要改為結束,請按 ESC。Press escape if you'd like to exit instead.

聚焦Focusing

有時候,您可能想要共同作業工作階段中的每個人都來查看您在處理的項目。Occasionally you may want everyone in a collaboration session to come and take a look at something you are doing. Live Share 可讓您要求所有人都將其注意力「聚焦」於您,並發出通知讓他們輕鬆回頭追蹤您。Live Share lets you ask that everyone "focus" their attention on you with a notification that makes it easy for them to follow you back.

請開啟 VS Code 活動列中的 Live Share 自訂索引標籤或 Live Share [總管] 檢視,然後選取 [聚焦參與者] 圖示。Open the Live Share custom tab in the VS Code activity bar or the Live Share Explorer view, and select the "Focus participants" icon.

聚焦 viewlet 圖示

在您執行命令之後,共同作業工作階段中的每個人就都會收到通知,指出您需要他們注意。Once you run the command, everyone in the collaboration session will then get a notification that you've requested their attention.

「請注意」快顯通知

當他們準備好要聚焦在您身上時,便可以直接按一下通知中的 [追蹤]。They can then just click "Follow" right from the notification when they're ready to put their focus on you.

共同偵錯Co-debugging

Visual Studio Live Share 的共同作業偵錯功能是功能強大且獨特的偵錯問題方式。Visual Studio Live Share's collaborative debugging feature is a powerful and unique way to debug an issue. 除了提供對問題進行偵錯的共同作業體驗之外,它也藉由在主持人的機器上提供共用偵錯工作階段,讓您和工作階段中的其他參與者有能力調查可能是環境特定的問題。Beyond enabling a collaborative experience to troubleshoot problems, it also gives you and other participants in your session the ability to investigate issues that may be environment specific by providing a shared debugging session on the host's machine.

安全性秘訣: 假設所有參與者都可以獨立地流覽和編輯檔案,身為主機,您可能會想要限制來賓能夠透過 .vsls.json 檔案在您的專案中存取的檔案。Security Tip: Given all participants can independently navigate and edit files, as a host, you may want to restrict which files guests are able to access in your project via a .vsls.json file. 您也應該留意到,主控台/REPL 存取表示參與者可以在您的機器上執行命令,因此您只應該與信任的人員進行共同偵錯。You should also be aware that Console/REPL access means that participants can execute commands on your machine so you should only co-debug with those you trust. 身為來賓,請務必了解到因為這些設定,所以當偵錯工具進入某些受限的檔案時,您可能無法追蹤它。As a guest, it is also important to realize you may not be able to follow the debugger as it steps into certain files restricted files as a result of these settings. 請參閱控制檔案存取權和可見性以取得詳細資料。See controlling file access and visibility for details.

使用它很簡單。Using it is simple.

  1. 請確定主持人和所有來賓皆已安裝適當的偵錯擴充。Be sure both the host and all guests have the appropriate debugging extension installed. (就技術性層面而言這並非必要,但通常是個不錯的主意。)(Technically this is not always necessary, but it is generally a good idea.)

  2. 身為主持人,如果您尚未針對專案進行設定,請設定 launch.json (英文) 以如往常一般地從 VS Code 對應用程式進行偵錯。As the host, if not already set up for the project, you should configure launch.json to debug the application from VS Code as you would normally. 您不需要進行任何特殊的設定。No special setup is required.

  3. 接下來,主持人可以開始如往常一般,使用偵錯索引標籤中的按鈕開始偵錯。Next, the host can start debugging using the button in the debug tab as normal.

    VS Code [偵錯] 按鈕

    提示

    您也可以從 VS Code 參與 Visual Studio 偵錯工作階段,反之亦然!You can also participate in Visual Studio debugging sessions from VS Code and vice versa! 如需詳細資訊,請參閱共同偵錯的 Visual Studio 指示Check out the Visual Studio instructions on co-debugging for more information.

偵錯工具附加在主持人端之後,所有來賓會也都會自動附加。Once the debugger attaches on the host's side, all guests are also automatically attached. 有一個偵錯「工作階段」在主持人的機器上執行的同時,所有參與者都會連線到該偵錯工作階段,且有他們自己的檢視。While there is one debugging "session" running on the host's machine, all participants are connected to it and have their own view.

已附加 VS Code 偵錯工具

任何人都可以逐步查看偵錯程序,這樣就能在共同作業者之間順暢地切換,而不需要交涉控制權。Anyone can step through the debugging process which enables seamless switching between collaborators without having to negotiate control.

注意

如需依語言或平台列出偵錯功能的狀態,請參閱平台支援See platform support for the state of debugging features by language or platform.

每個共同作業者都可以調查不同變數、跳到呼叫堆疊中的不同檔案、檢查變數,甚至新增或移除中斷點。Each collaborator can investigate different variables, jump to different files in the call stack, inspect variables, and even add or remove breakpoints. 共同編輯功能接著會允許每個參與者追蹤其他人的所在位置,以提供在「同時調查問題不同層面」與「共同作業偵錯」之間順暢切換的獨特功能。Co-editing features then allow each participant orator to track where the others are located to provide the unique ability to seamlessly switch between concurrently investigating different aspects of the problem and collaboratively debugging.

注意

不過,來賓在唯讀共同作業工作階段中將無法逐步執行偵錯程序。While in a read-only collaboration session, a guest will not be able to step through the debugging process. 但他們仍然可以新增或移除中斷點,及檢查變數。They can however, still add or remove breakpoints, and inspect variables.

並行偵錯的動畫

變更 VS Code 加入偵錯工作階段的時機Change when VS Code joins debugging sessions

根據預設,當主持人共用偵錯工作階段時,來賓會自動附加到該偵錯工作階段。By default, as a guest, you'll be automatically attached to debugging sessions when they are shared by the host. 不過,在某些情況下,您可能覺得此行為會造成干擾。However, in some cases, you may find this behavior disruptive. 幸運的是,您可以按照下列步驟來變更它:Fortunately, you can change it as follows:

請直接編輯 settings.json ([檔案] > [喜好設定] > [設定]),新增下列其中一行,然後重新啟動 VS Code:Simply edit settings.json (File > Preferences > Settings), add one of the following lines, and then restart VS Code:

設定Setting 行為Behavior
"liveshare.joinDebugSessionOption":"Automatic" 預設值。The default. 身為來賓,您會自動加入主持人啟動的任何偵錯工作階段。As a guest, you'll automatically join any shared debugging session the host starts.
"liveshare.joinDebugSessionOption":"Prompt" 身為來賓,當主持人啟動共用偵錯工作階段時,您會收到提示詢問您是否要加入。As a guest, you are prompted as to whether you want to join a shared debugging session when it is started by the host.
"liveshare.joinDebugSessionOption":"Manual" 身為來賓,您將需要手動加入任何偵錯工作階段。As a guest, you'll need to manually join any debugging sessions. 請參閱中斷連結與重新附加See detaching and reattaching.

中斷連結與重新附加Detaching and reattaching

身為來賓,您可能會想要暫時停止偵錯。As a guest, you may wish to stop debugging temporarily. 幸運的是,您可以直接按一下偵錯工具列中的「停止」圖示來將偵錯工具中斷連結,而不會影響主持人或其他來賓。Fortunately, you can simply click the "stop" icon in the debug toolbar to detach the debugger without affecting the host or other guests.

VS Code 偵錯工具 [停止] 按紐

如果您已更新設定來使自己不會自動附加,或是單純想要稍後再附加,您可以按 Ctrl+Shift+P / Cmd+Shift+P按一下工作階段狀態列項目,並選取 [附加至共用偵錯工作階段]。If you've updated settings so you no longer auto-attach or if you simply want to reattach later, you can do so by pressing Ctrl+Shift+P / Cmd+Shift+P or clicking on the session state status bar item and selecting "Attach to a Shared Debugging Session".

VS Code 附加偵錯工具

在瀏覽器中共用執行中的應用程式Sharing the running application in a browser

和 Visual Studio 針對如 ASP.NET 等的專案類型不同,Visual Studio Code 並不具有已知「Web 應用程式連接埠」的概念。Visual Studio Code does not have the concept of a known "web application port" like Visual Studio for project types such as ASP.NET. 不過,如果您是加入來自 Visual Studio 主持人的共同作業工作階段,當偵錯開始時,您可能會看見您的預設瀏覽器自動出現,其接著會自動連線至主持人正在執行的應用程式。However, if you are joining a collaboration session from a Visual Studio host, you may automatically see your default browser appear when debugging starts that is then automatically connected to the host's running applications. 請參閱 Visual Studio 功能以取得詳細資料。See Visual Studio features for more details.

身為主持人,您可以使用 [共用本機伺服器] 功能,來透過手動共用應用程式或如 RESTful 服務的其他端點以達成類似目的。As a host, you can achieve something similar by manually sharing the application or other endpoints like RESTful services using the "Share Local Server" feature. Visual Studio 和 VS Code 來賓接著可以在相同的 localhost 連接埠上開啟瀏覽器,以查看正在執行的應用程式。Visual Studio and VS Code guests can then open a browser on the same localhost port to see the running application. 請參閱共用伺服器以取得詳細資料。See share a server for more details.

共用伺服器Share a server

身為共同作業工作階段主持人,您可能偶爾會想要與來賓共用 Web 應用程式或其他在本機執行的伺服器或服務。From time to time, as a collaboration session host, you may find that you want to share a web application or other locally running servers or services with guests. 這可能是 RESTful 端點、資料庫和其他伺服器。This can range from other RESTful end-points to databases and other servers. Visual Studio Live Share 可讓您指定本機連接埠號碼,選擇性地為它命名,然後將它與所有來賓共用。Visual Studio Live Share lets you specify a local port number, optionally give it a name, and then share it with all guests.

然後來賓將能夠從其本機機器的相同連接埠存取您在該連接埠上共用的伺服器。The guests will then be able to access the server you shared on that port from their own local machine on the exact same port. 例如,如果您共用的 Web 伺服器是在連接埠 3000 上執行,則來賓也能在自己的機器上於 http://localhost:3000 存取相同的執行中 Web 伺服器!For example, if you shared a web server running on port 3000, the guest can access that same running web server on their own machine at http://localhost:3000! 這是透過主持人與來賓之間的 SSH 或 SSL 通道來達成,並且透過服務進行驗證,因此您可確定只有共同作業工作階段中的人員有存取權。This is accomplished via a secure SSH or SSL tunnel between the host and guests and authenticated via the service so you can be sure that only those in the collaboration session have access.

安全性秘訣: 身為主機,您應該對與來賓共用的埠有非常的選擇,並堅持應用程式埠(而不是共用系統埠)。Security Tip: As a host, you should be very selective with the ports you share with guests and stick to application ports (rather than sharing a system port). 對於來賓,共用連接埠的行為就如同該伺服器/服務是在他們自己的機器上執行。For guests, shared ports will behave exactly like they would if the server/service was running on their own machine. 這非常有用,但如果共用不適當的連接埠,也可能有風險。This is very useful, but if the wrong port is shared can also be risky.

基於安全性考量,其他來賓只能使用在您所指定的連接埠上執行的伺服器。For security purposes, only servers running on ports you specify are available to other guests. 幸好,您可以輕鬆地新增一個做為共同作業會話主機Fortunately, it's easy to add one as the collaboration session host. 方法:Here's how:

  1. 請開啟 VS Code 活動列中的 Live Share 自訂索引標籤或 Live Share [總管] 檢視,然後選取 [共用伺服器] 項目或按一下圖示。Open the Live Share custom tab in the VS Code activity bar or the Live Share Explorer view, and select the "Share server..." entry or click the icon.

    VS Code 共用本機伺服器

  2. 輸入伺服器所執行的連接埠號碼,並選擇性地提供名稱。Enter the port number the server is running on and optionally a name.

    連接埠號碼提示的螢幕擷取畫面

完成了!That's it! 您所指定連接埠上的伺服器,現在會對應到每個來賓 localhost 上的相同連接埠 (除非該連接埠已被占用)!The server on the port you specified will now be mapped to each guest's localhost on the same port (unless that port was already occupied)!

如果來賓機器上的該連接埠已經使用,系統會自動選取其他連接埠。If the port is already in use on the guest's machine, a different one is automatically selected. 幸運的是,身為來賓,您可以在 Live Share [總管] 檢視或 VS Code 活動列的自訂索引標籤中看見目前已共用的連接埠清單 (依名稱排序,若有提供的話),並查看 [共用伺服器] 清單底下。Fortunately, as a guest, you can see a list of currently shared ports (by name if specified) in the Live Share Explorer view or custom tab in the VS Code activity bar, and look under the shared servers list. 選取某個項目將會在您的瀏覽器中開啟該伺服器。Selecting an entry opens that server in your browser. 您也能以滑鼠右鍵按一下並選取將伺服器連結複製到剪貼簿的選項。You can also right click and select the option to copy the link to the server to the clipboard.

VS Code 存取本機伺服器

請注意,基於安全性考量,「來賓無法」** 控制在主持人機器上要共用哪個連接埠。Note that guests cannot control which ports on the host's machine are shared for security reasons.

若要以主持人身分停止共用本機伺服器,請在 Live Share [總管] 檢視或自訂索引標籤的共用伺服器清單中將游標暫留於該伺服器項目上方,然後按一下 [取消共用伺服器] 圖示。To stop sharing a local server as the host, hover over the server entry in the shared servers list in the Live Share Explorer view or custom tab, and click the "Unshare server" icon.

VS Code 停止共用伺服器

共用終端機Share a terminal

新式開發經常會運用各種命令列工具。Modern development makes frequent use of a wide array of command line tools. 幸運的是,Live Share 可讓身為主持人的您選擇與來賓「共用終端機」。Fortunately, Live Share allows you, as a host, to optionally "share a terminal" with guests. 共用的終端機可以是唯讀或完全共同作業,因此您和您的來賓都能執行命令並看到結果。The shared terminal can be read-only or fully collaborative so both you and the guests can run commands and see the results. 您可以讓來賓看得到終端機輸出,或讓他們操作或執行測試、建置,或甚至將只發生在您機器上的環境特定問題分級。You can to give guests visibility to terminal output or let them get hands-on and run tests, builds, or even triage environment-specific problems that only happen on your machine.

不過,根據預設共用終端機,因為它們至少提供來賓您所執行命令之輸出的唯讀存取權 (若他們無法自行執行命令)。However, terminals are not shared by default since they give guests at least read-only access to the output of commands you run (if not the ability to run commands themselves). 這樣一來,您可以沒有風險地自由在本機終端機上執行命令,並且只在需要時進行共用。This way you can freely run commands in local terminals without risk and only share when actually need to do so. 此外,只有主持人可以啟動共用終端機,這可以防止來賓啟動共用終端機並進行您未預期或您看不到的操作。In addition, only hosts can start shared terminals to prevent guests from starting one up and doing something you are not expecting or watching.

身為主持人,您可以開啟 VS Code 活動列中的 [Live Share] 自訂索引標籤或 Live Share [總管] 檢視,然後選取 [共用伺服器] 項目或按一下圖示來共用終端機。As a host, you can share a terminal by opening the Live Share custom tab in the VS Code activity bar or the Live Share Explorer view, and selecting the "Share server..." entry or clicking the icon.

VS Code 共用終端機

此時,您可以從功能表中選取唯讀或讀取/寫入終端機。At this point, you can select a read-only or read/write terminal from the menu. 當終端機是讀取/寫入時,包括主持人在內的每個人都可以在終端機中輸入,這樣當來賓在進行您不希望的操作時,您輕鬆就能介入。When the terminal is read/write, everyone can type in the terminal including the host which makes it easy to intervene if a guest is doing something you do not like. 不過,為了安全起見,您應該只在確定來賓確實需要讀取/寫入存取權時才提供此權限,並在您只想要來賓查看您執行之任何命令的輸出時提供唯讀終端機。However, to be safe, you should only give read/write access to guests when you know they actually need it and stick with read-only terminals for scenarios where you just want the guest to see the output of any commands you run. 請記住,讀取/寫入存取權會提供來賓與您的終端機相同的存取權,而且可以在您的電腦上執行您可以的任何命令。Keep in mind that read/write access gives the guest the same access to your terminal that you have, and they can run any command on your computer that you can.

注意

如果共同作業工作階段是處於唯讀模式,主持人就只能共用唯讀終端機。If the collaboration session is in read-only mode, only read-only terminals can be shared by the host.

唯讀或讀取/寫入選取項目

一旦您選取要啟動的共用終端機類型,VS Code [終端機] 索引標籤底下將會出現新的共用終端機。Once you've selected the kind of shared terminal you want to start, a new shared terminal will appear under VS Code's terminals tab.

執行中的共用終端機

如果已共用多個終端機,或是您的焦點位於不同的索引標籤中,您可以透過選取共用終端機清單中的項目來將焦點移至特定的終端機。If multiple terminals are shared, or your focus is in a different tab, you can bring focus to a specific terminal by selecting the entry in the shared terminals list.

共用終端機能轉移焦點

若要結束終端機工作階段,請直接輸入 exit、關閉終端機視窗,或按一下 Live Share [總管] 檢視或自訂索引標籤中的 [取消共用終端機],所有人的連線便會中斷。To end your terminal session, simply type exit, close the terminal window, or click the "Unshare terminal" icon in the Live Share Explorer view or custom tab and everyone will be disconnected.

工作階段狀態Session states

當您已經啟動或加入共同作業工作階段,並且可存取共用內容之後,Visual Studio Live Share 狀態列項目便會更新其外觀,以反映使用中共同作業工作階段的狀態。After you have started or joined collaboration session and have access to shared content, the Visual Studio Live Share status bar items update their appearance to reflect the state of the active collaboration session.

下列是您通常會看到的狀態:The following are the states you will typically see:

State 狀態列Status Bar DescriptionDescription
非使用中Inactive VS Code 狀態:非使用中 沒有任何作用中的共同作業工作階段,且未共用任何項目。No active collaboration session and nothing is shared.
主機:共用進行中Host: Sharing In-Progress VS Code 狀態:共用正在進行中 正在啟動共同作業工作階段,且共用內容很快就會開始。A collaboration session is starting and content sharing will begin shortly.
主機:共用Host: Sharing VS Code 狀態:共用作用中VS Code status: sharing active 共同作業工作階段已啟動,且已共用內容。A collaboration session is active and content is shared.
主機:共用唯讀Host: Sharing Read-only VS Code 狀態:正在共用唯讀 正在共用唯讀共同作業工作階段。Sharing a read-only collaboration session.
來賓:正在加入會話Guest: Joining Session VS Code 狀態:正在加入 正在加入現有共同作業工作階段。Joining an existing collaboration session.
來賓:已加入Guest: Joined VS Code 狀態:已加入 已加入且連線至使用中的共同作業工作階段,並接收共用內容。Joined and connected to an active collaboration session and receiving shared content.
Guest:已加入唯讀Guest: Joined Read-only VS Code 狀態:已加入唯讀 已加入且連線至使用中的唯讀共同作業工作階段。Joined and connected to an active read-only collaboration session.

來賓限制Guest limitations

雖然目前來賓在使用上述功能時會遇到一些缺點,但共同作業工作階段主持人會保有所選工具的完整功能。While there are currently some shortcomings guests will experience while using the features described above, collaboration session hosts retain the complete functionality of their tool of choice. 如需詳細資訊,請參閱下列主題:See the following for more information:

後續步驟Next steps

請查看下列其他文章以取得詳細資訊。Check out these additional articles for more information.

有問題嗎?Having problems? 請參閱疑難排解提供意見反應See troubleshooting or provide feedback.