Visual Studio for Mac 是否支援 Team Foundation 版本控制?Does Visual Studio for Mac support Team Foundation Version Control?

警告

Visual Studio 2019 for Mac 已不再支援 Visual Studio for Mac 的 TFVC 延伸模組預覽版本。The preview TFVC extension for Visual Studio for Mac is no longer supported in Visual Studio 2019 for Mac.

Visual Studio for Mac 中的替代版本控制選項Alternative Version Control options in Visual Studio for Mac

為了獲得最佳的 macOS 版本控制體驗,我們建議使用 Git ,而不是 TEAM FOUNDATION 版本控制 (TFVC) 。For the best version control experience on macOS, we recommend using Git instead of Team Foundation Version Control (TFVC).

Visual Studio for Mac 支援 Git,它是 Team Foundation Server (TFS)/Azure DevOps 中裝載之存放庫的預設選項。Git is supported in Visual Studio for Mac and is the default option for repositories hosted in Team Foundation Server (TFS)/Azure DevOps. 若要深入了解有關搭配 TFS/Azure DevOps 使用 Git 的詳細資訊,請參閱設定 Git 存放庫指南。To learn more about using Git with TFS/Azure DevOps, see the Setting up a Git Repository guide.

不支援的 TFVC 因應措施Unsupported workarounds for TFVC

雖然 Visual Studio for Mac 為正式支援 TFVC,但此指南的剩餘部分提供在 macOS 上使用 TFVC 的一些因應措施。While Visual Studio for Mac doesn't officially support TFVC, the rest of this guide provides some workarounds to work with TFVC on macOS. 如果您今天使用 TFVC 進行版本控制,可以使用以下解決方案來存取 TFVC 中裝載的原始程式碼:If you're using TFVC for version control today, here are some solutions you can use to access your source code hosted in TFVC:

選項 1。Option 1. 使用 Visual Studio Code 和 Azure Repos 擴充功能Use Visual Studio Code and the Azure Repos extension

如果您希望使用圖形化介面來管理版本控制中的檔案,則 Visual Studio Code 的 Azure Repos 延伸模組可提供由 Microsoft 支援的解決方案。If you like to work with a graphical interface to manage your files in version control, then the Azure Repos extension for Visual Studio Code provides a supported solution from Microsoft. 若要開始使用,請下載 Visual Studio Code,然後了解如何設定 Azure Repos 延伸模組To get started, download Visual Studio Code and then learn how to configure the Azure Repos extension.

選項 2。Option 2. 使用 Team Explorer Everywhere 命令列用戶端連接Connecting using the Team Explorer Everywhere Command Line Client

重要

作為 Team Explorer Everywhere README 的一部分,我們已不再維護此專案As per the Team Explorer Everywhere README, this project is no longer being maintained.

如果您習慣使用 macOS 終端機,那麼 Team Explorer Everywhere 命令列用戶端 (TEE CLC) 會提供支援的方法,來連線到您在 TFVC 中的來源。If you're comfortable using the macOS Terminal, then the Team Explorer Everywhere Command Line Client (TEE-CLC) provides a supported way to connect to your source in TFVC.

您可以遵循下列步驟來設定與 TFVC 的連線並認可變更。You can follow the steps below to set up your connection to TFVC and commit changes.

設定 TEE-CLCSetting up the TEE-CLC

有兩種方法可以使用 TEE-CLC 進行安裝。There are two ways to get setup with the TEE-CLC.

  • 使用 Homebrew 安裝用戶端,或Use Homebrew to install the client, or
  • 下載並手動安裝用戶端Download and manually install the client

最簡單的解決方案是 使用 HomeBrew,這是適用於 macOS 的套件管理員。The easiest solution is using HomeBrew, which is a package manager for macOS. 若要使用此方法進行安裝:To install using this method:

  1. 啟動 macOS 終端機應用程式。Launch the macOS Terminal application.
  2. 使用終端機和 Homebrew 首頁上的說明安裝 Homebrew。Install Homebrew using the Terminal and the instructions on the Homebrew home page.
  3. 安裝 Homebrew 之後,請從您的終端機執行下列命令:brew install tee-clcOnce Homebrew is installed, run the following command from your Terminal: brew install tee-clc

手動設定 TEE CLCTo setup the TEE-CLC manually:

  1. 從 Team Explorer Everywhere GitHub 儲存機制的 [版本] 頁面下載最新版本的 tee-clc (例如撰寫本文時的 tee-clc-14.134.0.zip)。Download the latest version of the tee-clc from the releases page of the Team Explorer Everywhere GitHub repo (e.g. tee-clc-14.134.0.zip at the time of this writing).
  2. 將 .zip 的內容解壓縮到磁碟上的資料夾。Extract the content of the .zip to a folder on disk.
  3. 開啟 macOS 終端機應用程式,並使用 cd 命令切換至您在上一個步驟中使用的資料夾。Open the macOS Terminal app and use the cd command to switch to the folder you used in the previous step.
  4. 在資料夾中,執行命令 ./tf 以測試是否可以執行命令列用戶端,系統可能會提示您安裝 Java 或其他相依性。From within the folder, run the command ./tf to test that the command line client can run, you may be prompted to install Java or other dependencies.

安裝 TEE-CLC 之後,您可以執行命令 tf eula 來檢視並接受用戶端的授權合約。Once the TEE-CLC is installed, you can run the command tf eula to view and accept the license agreement for the client.

最後,若要使用 TFS/Azure DevOps 環境進行驗證,您需要在伺服器上建立個人存取權杖。Finally, to authenticate with your TFS/Azure DevOps environment, you'll need to create a personal access token on the server. 深入了解使用個人存取權杖進行驗證Learn more about authenticating with personal access tokens. 建立用於 TFVC 的個人存取權杖時,請確保在設定權杖時提供完整的存取權。When creating a personal access token to use with TFVC, be sure to provide Full Access when configuring the token.

使用 TEE-CLC 連線到您的存放庫Using the TEE-CLC to connect to your repo

若要連線到您的原始程式碼,首先需要使用 tf workspace 命令建立工作區。To connect to your source code, you first need to create a workspace using the tf workspace command. 例如,下列命令會連線到名為 "MyOrganization" 的 Azure DevOps Services 中的組織:For example, the following commands connect to an Organization in Azure DevOps Services called "MyOrganization":

export TF_AUTO_SAVE_CREDENTIALS=1
tf workspace -new MyWorkspace -collection:https://dev.azure.com/MyOrganization

TF_AUTO_SAVE_CREDENTIALS 環境設定用來儲存您的認證,因此系統不會提示您輸入多次認證。The TF_AUTO_SAVE_CREDENTIALS environment setting is used to save your credentials so you aren't prompted to enter them multiple times. 當系統提示輸入使用者名稱時,請使用您在上一節中建立的個人存取權杖並使用空白密碼。When prompted for a user name, use the personal access token you created in the previous section and use a blank password.

若要建立來源檔案到本機資料夾的對應,您將使用 tf workfold 命令。To create a mapping of your source files to a local folder, you'll use the tf workfold command. 下列範例會對應 "MyRepository" TFVC 專案中名為 "WebApp.Services" 的資料夾,並將它設定為複製到本機 ~/Projects/ 資料夾中 (例如,目前使用者主資料夾中的 "Projects" 資料夾)。The following example will map a folder named "WebApp.Services" from the "MyRepository" TFVC project and set it up to be copied into the local ~/Projects/ folder (i.e. a "Projects" folder in the current users's home folder).

tf workfold -map $/MyRepository/WebApp.Services -workspace:MyWorkspace ~/Projects/

最後,使用下列命令從伺服器取得來源檔案,並將其複製到本機:Finally, you use the following command to get the source files from the server and copy them locally:

tf get

使用 TEE-CLC 認可變更Committing changes using the TEE-CLC

在 Visual Studio for Mac 中對檔案進行變更後,可以切換回終端機以簽入編輯內容。After you've made changes to your files in Visual Studio for Mac, you can switch back to the Terminal to check in your edits. tf add 命令用於將檔案新增至要簽入的暫止變更清單中,而 tf checkin 命令執行對伺服器的實際簽入。The tf add command is used to add files to the list of pending changes to be checked-in and the tf checkin command performs the actual check-in to the server. checkin 命令包括用於新增註解或產生相關工作項目關聯的參數。The checkin command includes parameters to add a comment or associate a related work item. 在下列程式碼片段中,WebApp.Services 資料夾中的所有檔案將以遞迴方式新增到簽入中。In the following code snippet, all files in a WebApp.Services folder are added, recursively, to the checkin. 然後,使用註解簽入程式碼,並將其與識別碼為 "42" 的工作項目相關聯。Then, the code is checked in with a comment and associated with a work item with the ID "42".

cd WebApp.Services
tf add * /recursive
tf checkin -comment:"Replaced 'Northwand' typos with the correct word Northwind" -associate:42

若要深入了解有關此處所述的命令或其他命令的詳細資訊,您可以從終端機使用下列命令:To learn more about the commands mentioned here, or others, you can use the following command from the Terminal:

tf help

另請參閱See also