作法:為 Visual Studio 命令列設定環境變數How to: Set Environment Variables for the Visual Studio Command Line

VsDevCmd.bat 檔案可設定適當的環境變數,以啟用命令列組建。The VsDevCmd.bat file sets the appropriate environment variables to enable command-line builds.

注意

VsDevCmd.bat 檔是隨附於 Visual Studio 2017 的新檔案。The VsDevCmd.bat file is a new file delivered with Visual Studio 2017. Visual Studio 2015 及更早的版本則使用 VSVARS32.bat 作為相同用途。Visual Studio 2015 and earlier versions used VSVARS32.bat for the same purpose. 此檔案的儲存位置為 \Program Files\Microsoft Visual Studio\Version\Common7\Tools or Program Files (x86)\Microsoft Visual Studio\Version\Common7\Tools。This file was stored in \Program Files\Microsoft Visual Studio\Version\Common7\Tools or Program Files (x86)\Microsoft Visual Studio\Version\Common7\Tools.

如果安裝最新版 Visual Studio 的電腦上也有安裝舊版 Visual Studio,請勿於相同的命令提示字元視窗中,執行不同版本的 VsDevCmd.bat 及 VSVARS32.BAT。If the current version of Visual Studio is installed on a computer that also has an earlier version of Visual Studio, you should not run VsDevCmd.bat and VSVARS32.BAT from different versions in the same Command Prompt window. 而是應改為在各版本本身的視窗中執行命令。Instead, you should run the command for each version in its own window.

執行 VsDevCmd.BATTo run VsDevCmd.BAT

  1. 從 [開始] 功能表中,開啟 [適用於 VS 2017 的開發人員命令提示字元] 。From the Start menu, open the Developer Command Prompt for VS 2017. 位置在 Visual Studio 2017 資料夾中。It's in the Visual Studio 2017 folder.

  2. 根據您的安裝變更到 \Program Files\Microsoft Visual Studio\Version\Offering\Common7\Tools 或是 \Program Files (x86)\Microsoft Visual Studio\Version\Offering\Common7\Tools 子目錄。Change to the \Program Files\Microsoft Visual Studio\Version\Offering\Common7\Tools or \Program Files (x86)\Microsoft Visual Studio\Version\Offering\Common7\Tools subdirectory of your installation. (目前的版本2017(Version is 2017 for the current version. 供應項目EnterpriseProfessionalCommunity 中的其中一個。)Offering is one of Enterprise, Professional or Community.)

  3. 鍵入 VsDevCmd以執行 VsDevCmd.bat。Run VsDevCmd.bat by typing VsDevCmd.

    警告

    在不同的電腦上,VsDevCmd.bat 檔案可能也不同。VsDevCmd.bat can vary from computer to computer. 請勿使用另一部電腦的 VsDevCmd.bat 來取代遺失或損毀的 VsDevCmd.bat 檔案。Do not replace a missing or damaged VsDevCmd.bat file with a VsDevCmd.bat from another computer. 請重新執行安裝程式以取代遺失的檔案。Instead, rerun setup to replace the missing file.

適用於 VsDevCmd.BAT 的可用選項Available options for VsDevCmd.BAT

若要查看適用於 VsDevCmd.BAT 的可用選項,請搭配 -help 選項執行命令:To see the available options for VsDevCmd.BAT, run the command with the -help option:

VsDevCmd.bat -help

另請參閱See also