使用 Visual Studio 在 TFVC 中開發和共用程式代碼

Azure DevOps Services |Azure DevOps Server 2022 - Azure DevOps Server 2019 |TFS 2018

Visual Studio 2019 |Visual Studio 2022

無論您的軟體專案是大型、小型或全新的,最好儘早使用版本控制。 本文說明如何開始使用 Team Foundation 版本控制 (TFVC),這是集中式版本控制系統。

  • 如果您想要在分散式版本控制系統中運作,您可以改用 Git 搭配 Azure Repos

  • 如果您有想要移轉至 Azure DevOps Services 的程式代碼,請參閱 移轉選項

必要條件

連線 至您的專案

  1. 在 Visual Studio 中,從 [Team Explorer] 的 [首頁] 頁面中,選取 [管理 連線] 圖示。

  2. [Team Explorer] 的 [連線] 頁面上,以滑鼠右鍵按兩下包含存放庫的項目,然後選取 [連線]。

    Screenshot that shows selecting Connect to connect a project.

    如果未列出您想要的專案,請選取 [管理 連線,選取 [連線 至專案],然後選取您想要的專案。 如需詳細資訊,請參閱從 Visual Studio 或 Team Explorer 連線。

注意

在您連線到 TFVC 之前,某些 TFVC 功能表選項不會顯示在 Visual Studio 中。

設定工作區

  1. Visual Studio Team Explorer 的 [首頁] 頁面上,選取 [設定工作區] 將專案對應至開發電腦上的資料夾。

  2. 確認您的工作區路徑,然後選取 [對應和取得 ] 來對應工作區並取得您的程序代碼。

    Screenshot that shows mapping the workspace to get code.

    現在您可以簽入來源、佇列組建及管理工作。

    Screenshot shows a success message that verifies that Visual Studio is now connected to your project.

如果您沒有看到 [ 設定工作區 ] 連結,您可能已經在計算機上有工作區。 若要查看現有的工作區,請開啟原始檔控制總管,或查看 [Team Explorer 中的方案] 底下。 如需詳細資訊,請參閱 使用原始檔控制總管來管理 TFVC 中的檔案和 建立和使用工作區

Screenshot that shows Team Explorer, where you can select Source Control Explorer or Manage Workspaces.

注意

TFVC 不支援網路驅動器機或 UNC 路徑上的工作區。

將程式代碼新增至版本控制

  1. 若要建立新的程式碼專案以置於 TFVC 原始檔控制之下,請在 Team Explorer 的 [首頁] 頁面中選取 [新增]。 將新方案放在對應的工作區資料夾中,例如 c:\Users\YourName>\Source\<Workspaces\YourTeamProject\

    Screenshot that shows the Team Explorer Home page with New highlighted under Solutions.

    或者,如果您已經有想要置於 TFVC 原始檔控制之下的應用程式進行中,請將解決方案移至 Windows 檔案總管 中的工作區資料夾。

    Screenshot shows moving your source code to your workspace folder.

  2. 在 Visual Studio 中開啟您的方案。

    Screenshot shows Team Explorer Home page, where you can open your solution in Visual Studio.

  3. 按 Ctrl+Alt+L 以開啟 方案總管,然後在 方案總管,以滑鼠右鍵按兩下方案,然後選取 [將方案新增至原始檔控制]。

    Screenshot of adding your solution to source control.

  4. 在 [ 將方案新增至原始檔控制 ] 對話框中,檢閱詳細數據,然後選取 [ 確定]。

簽入解決方案

  1. 當您準備好簽入程式代碼時,請在 方案總管以滑鼠右鍵按下您的解決方案,然後選取 [簽到]。

    Screenshot that shows a context menu with Check In selected.

  2. 在 Team Explorer 的 [擱置變更] 頁面上,新增簽入批注,然後選取 [簽入]。

    Screenshot that shows a Pending Changes pane with a comment and a Check In button.

  3. 從 [Team Explorer] 的 [首頁] 中,選取 [原始檔控制總管]。

    Screenshot that shows the Team Explorer Home page with Source Control Explorer selected.

    原始檔控制總管中,您可以在 TFVC 中看到解決方案。

    Screenshot that shows the solution in Source Control Explorer.

您的整個小組現在可以處理程序代碼。 所有變更都會在版本控制中追蹤。

簽入變更

  1. 當您在 TFVC 原始檔控制下的 Visual Studio 中編輯程式代碼時,會自動取出已變更的檔案。例如,在 變更為 16px之後font-size,就會取出 site.css

    Screenshot that shows Solutions Explorer with the file site.css checked out.

  2. 若要比較修改過的檔案與原始檔控制中的最新版本,請以滑鼠右鍵按兩下 方案總管 中的檔案,然後選取 [比較]。

    Screenshot that shows the Compare option in the Solution Explorer context menu.

    [差異] 視窗隨即開啟,您可以看到兩個版本之間的差異。

    Screenshot that shows the compare window, with two versions of the file side by side.

  3. [方案總管] 中,以滑鼠右鍵按兩下檔案,然後選取 [簽到] 以存回變更。

    Screenshot that shows the Check In option in the Solution Explorer context menu.

    您也可以從程式代碼編輯器或 Team Explorer 簽入。

  4. 如果您正在處理工作或修正追蹤為工作專案的 Bug,您可以將該工作專案與擱置的變更產生關聯。 TFVC 會解決 Bug、關閉工作,或將變更集連結至工作專案。

    Screenshot shows Related Work Items in pending changes.

  5. 新增批注並簽入。

    Screenshot that shows where you can add a comment and check in the files.

  6. [原始檔控制總管] 中,以滑鼠右鍵按下您變更的檔案,然後選取 [ 檢視歷程記錄 ] 以檢視其歷程記錄。

    Screenshot that shows View History in the source file context menu.

    [ 歷程記錄] 視窗會列出包含此檔案的所有變更集。

    Screenshot that shows the History window with changesets.

下一步