以 Visual Studio Code 在本機執行 U-SQL 及偵錯Run U-SQL and debug locally in Visual Studio Code

本文說明如何在本機開發電腦上執行 U-SQL 作業,以便加速早期的編碼階段,或以 Visual Studio Code 在本機對程式碼進行偵錯。This article describes how to run U-SQL jobs on a local development machine to speed up early coding phases or to debug code locally in Visual Studio Code. 如需如何使用 Azure Data Lake Tools for Visual Studio Code 的指示,請參閱使用 Azure Data Lake Tools for Visual Studio CodeFor instructions on Azure Data Lake Tool for Visual Studio Code, see Use Azure Data Lake Tools for Visual Studio Code.

只有 Windows 安裝的 Azure Data Lake Tools for Visual Studio,才支援在本機執行 U-SQL 並在本機偵錯 U-SQL 的動作。Only Windows installations of the Azure Data Lake Tools for Visual Studio support the action to run U-SQL locally and debug U-SQL locally. 若安裝在以 macOS 和 Linux 為基礎的作業系統上,則不支援這項功能。Installations on macOS and Linux-based operating systems do not support this feature.

設定 U-SQL 本機執行環境Set up the U-SQL local run environment

  1. 選取 Ctrl + Shift + P 以開啟命令選擇區,然後輸入 **ADL:下載本機執行封裝 @ no__t-0 以下載套件。Select Ctrl+Shift+P to open the command palette, and then enter ADL: Download Local Run Package to download the packages.

    下載 ADL LocalRun 相依性套件

  2. 從 [輸出] 窗格中顯示的路徑找出相依性套件,然後安裝 BuildTools 和 Win10SDK 10240。Locate the dependency packages from the path shown in the Output pane, and then install BuildTools and Win10SDK 10240. 路徑範例如下:Here is an example path:
    C:\Users\xxx\AppData\Roaming\LocalRunDependency

    找出相依性套件

    2.1 如果要安裝 BuildTools,按一下 LocalRunDependency 資料夾中的 visualcppbuildtools_full.exe,然後遵循精靈的指示。2.1 To install BuildTools, click visualcppbuildtools_full.exe in the LocalRunDependency folder, then follow the wizard instructions.

    安裝 BuildTools

    2.2 如果要安裝 Win10SDK 10240,按一下 LocalRunDependency/Win10SDK_10.0.10240_2 資料夾中的 sdksetup.exe,然後遵循精靈的指示。2.2 To install Win10SDK 10240, click sdksetup.exe in the LocalRunDependency/Win10SDK_10.0.10240_2 folder, then follow the wizard instructions.

    安裝 Win10SDK 10240

  3. 設定環境變數。Set up the environment variable. SCOPE_CPP_SDK 環境變數設定為:Set the SCOPE_CPP_SDK environment variable to:
    C:\Users\XXX\AppData\Roaming\LocalRunDependency\CppSDK_3rdparty

啟動本機執行服務並將 U-SQL 作業提交給本機帳戶Start the local run service and submit the U-SQL job to a local account

對於第一次使用者,請使用 **ADL:如果您尚未 設定 U-SQL 本機執行環境,請下載本機執行封裝 @ no__t-0 以下載本機執行套件。For the first-time user, use ADL: Download Local Run Package to download local run packages, if you have not set up U-SQL local run environment.

  1. 選取 Ctrl + Shift + P 以開啟命令選擇區,然後輸入 **ADL:啟動本機執行服務 @ no__t-0。Select Ctrl+Shift+P to open the command palette, and then enter ADL: Start Local Run Service.

  2. 選取 [接受] 來首次接受 Microsoft 軟體授權條款。Select Accept to accept the Microsoft Software License Terms for the first time.

    接受 Microsoft 軟體授權條款

  3. 隨即會開啟 CMD 主控台。The cmd console opens. 如果您是初次使用者,就必須輸入 3,然後找出用於資料輸入和輸出的本機資料夾路徑。For first-time users, you need to enter 3, and then locate the local folder path for your data input and output. 如果您不成功定義具有反斜線的路徑,請嘗試使用正斜線。If you are unsuccessful defining the path with backslashes, try forward slashes. 其他選項則可以使用預設值。For other options, you can use the default values.

    Data Lake Tools for Visual Studio Code 本機執行 CMD

  4. 選取 Ctrl + Shift + P 以開啟命令選擇區,並輸入 @no__t 0ADL:提交作業 @ no__t-0,然後選取 [本機] 將作業提交至您的本機帳戶。Select Ctrl+Shift+P to open the command palette, enter ADL: Submit Job, and then select Local to submit the job to your local account.

    Data Lake Tools for Visual Studio Code 選取本機

  5. 在提交作業後,您就可以檢視提交詳細資料。After you submit the job, you can view the submission details. 若要檢視提交詳細資料,選取 [輸出] 視窗中的 [jobUrl]。To view the submission details, select jobUrl in the Output window. 您也可以從 CMD 主控台檢視作業提交狀態。You can also view the job submission status from the cmd console. 如果您想要知道更多的作業詳細資料,請在 CMD 主控台中輸入 7Enter 7 in the cmd console if you want to know more job details.

    Data Lake Tools for Visual Studio Code 本機執行輸出 Data Lake Tools for Visual Studio Code 本機執行 CMD 狀態Data Lake Tools for Visual Studio Code local run output Data Lake Tools for Visual Studio Code local run cmd status

開始 U-SQL 作業的本機偵錯Start a local debug for the U-SQL job

初次使用者:For the first-time user:

  1. 使用 **ADL:如果您尚未 設定 U-SQL 本機執行環境,請下載本機執行封裝 @ no__t-0 以下載本機執行套件。Use ADL: Download Local Run Package to download local run packages, if you have not set up U-SQL local run environment.

  2. 如訊息方塊中所建議安裝 .NET Core SDK 2.0 (如果未安裝的話)。Install .NET Core SDK 2.0 as suggested in the message box, if not installed.   @ no__t-1reminder 會安裝 Dotnet @ no__t-2  reminder installs Dotnet

  3. 如C#未安裝,請依照訊息方塊中的建議安裝 Visual Studio Code。Install C# for Visual Studio Code as suggested in the message box if not installed. 按一下 [安裝] 繼續作業,然後重新啟動 VSCode。 Click Install to continue, and then restart VSCode.

    提醒安裝 C#

遵循下列步驟執行本機偵錯:Follow steps below to perform local debug:

  1. 選取 Ctrl + Shift + P 以開啟命令選擇區,然後輸入 **ADL:啟動本機執行服務 @ no__t-0。Select Ctrl+Shift+P to open the command palette, and then enter ADL: Start Local Run Service. 隨即會開啟 CMD 主控台。The cmd console opens. 請確定您已設定 DataRootMake sure that the DataRoot is set.

  2. 在您的 C# 程式碼後置中設定中斷點。Set a breakpoint in your C# code-behind.

  3. 回到腳本編輯器,以滑鼠右鍵按一下並選取 [**ADL]:本機 Debug @ no__t-0。Back to script editor, right-click and select ADL: Local Debug.

    Data Lake Tools for Visual Studio Code 本機偵錯結果

後續步驟Next steps