Visual Studio 开发人员命令提示Developer Command Prompt for Visual Studio

Visual Studio 的开发人员命令提示使你可以更轻松地使用 .NET Framework 工具。Developer Command Prompt for Visual Studio enables you to use .NET Framework tools more easily. 它是一个自动设置特定环境变量的命令提示符。It's a command prompt that automatically sets specific environment variables. 打开开发人员命令提示后,可以为 .NET Framework 工具(如 ildasmclrver)输入命令。After opening Developer Command Prompt, you can enter the commands for .NET Framework tools such as ildasm or clrver.

先决条件Prerequisites

在计算机中搜索命令提示符Search for the command prompt on your machine

你可能会有多个命令提示符,具体取决于你安装的 Visual Studio 的版本及其他任何 SDK 和工作负载。You may have multiple command prompts, depending on the version of Visual Studio and any additional SDKs and workloads you've installed. 如果以下步骤不起作用,可以尝试在计算机中手动查找文件从 Visual Studio 内部启动命令提示符If the following steps don't work, you can try to manually locate the files on your machine or start the command prompt from inside Visual Studio.

Windows 10Windows 10

  1. 选择“开始”键盘上的 Windows 徽标键。Select Start Windows logo key on the keyboard. 并滚动到字母“V”。and scroll to the letter V.

  2. 展开“Visual Studio 2019”文件夹。Expand the Visual Studio 2019 folder.

  3. 选择“VS 2019 开发人员命令提示”(或者你想使用的命令提示符)。Choose Developer Command Prompt for VS 2019 (or the command prompt you want to use).

    或者,你可以首先在任务栏的搜索框中键入命令提示符的名称,然后在结果列表开始显示搜索匹配项时选择所需的结果。Alternatively, you can start typing the name of the command prompt in the search box on the taskbar, and choose the result you want as the result list starts to display the search matches.

    在 Windows 10 上显示搜索行为的动画 gif

Windows 8.1Windows 8.1

  1. 按 Windows 徽标键键盘上的 Windows 徽标键,转到“开始”屏幕。Go to the Start screen, by pressing the Windows logo key Windows logo key on the keyboard. 例如,在键盘上。on your keyboard for example.

  2. 在“开始”屏幕上,按 Ctrl+Tab 打开“应用程序”列表,然后按 V。然后显示一个列表,其中包含所有已安装的 Visual Studio 命令提示。On the Start screen, press Ctrl+Tab to open the Apps list, and then press V. This brings up a list that includes all installed Visual Studio command prompts.

  3. 选择“VS 2019 开发人员命令提示”(或者你想使用的命令提示符)。Choose Developer Command Prompt for VS 2019 (or the command prompt you want to use).

Windows 7Windows 7

  1. 选择“开始”,然后展开“所有程序”。Choose Start and then expand All Programs.

  2. 选择“Visual Studio 2019” > “Visual Studio Tools” > “VS 2019 开发人员命令提示”,或者你想使用的命令提示。Choose Visual Studio 2019 > Visual Studio Tools > Developer Command Prompt for VS 2019, or the command prompt you want to use.

    突出显示命令提示符的 Windows 7“开始”菜单

如果安装了其他 SDK,例如 Windows 10 SDK之前的版本,则可能看到其他命令提示符。If you have other SDKs installed, such as the Windows 10 SDK or previous versions, you may see additional command prompts. 查看单个工具的文档,以确定应使用哪个版本的命令提示。Check the documentation for the individual tools to determine which version of the command prompt you should use.

在计算机中手动查找文件Manually locate the files on your machine

已安装的命令提示符的快捷方式通常放在 Visual Studio 的“开始菜单”文件夹中,例如 %ProgramData%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools。Usually, the shortcuts for the command prompts you have installed are placed at the Start Menu folder for Visual Studio, such as in %ProgramData%\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools. 但是如果出于某种原因,搜索命令提示未产生预期的效果,你可以尝试在计算机中手动查找快捷方式。But if, for some reason, searching for the command prompt doesn't produce the expected results, you can try to manually locate the shortcut on your machine. 请尝试搜索命令提示符文件的名称,例如 VsDevCmd.bat,或者转到“工具”文件夹,例如 %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Tools(该路径根据你的 Visual Studio 版本和安装位置而变化)。Try searching for the name of the command prompt file, such as VsDevCmd.bat, or go to the Tools folder, such as %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Tools (path changes according to your Visual Studio version, edition, and installation location).

从 Visual Studio 内部启动命令提示符Start the command prompt from inside Visual Studio

为便于访问,你可以将开发人员命令提示或其他任何命令提示符添加到 Visual Studio 中的“工具”菜单中。For easier access, you can add Developer Command Prompt, or any other command prompt, to the Tools menu in Visual Studio. 要使该工具可用,请将其添加到外部工具列表中。To make the tool available, add it to the external tools list. 步骤如下:Here are the steps:

  1. 打开 Visual Studio。Open Visual Studio.

  2. 在“启动”窗口中,选择“继续但无需代码”。On the start window, choose Continue without code.

  3. 在菜单栏上,依次选择“工具” > “外部工具”。On the menu bar, choose Tools > External Tools.

  4. 在“外部工具”对话框中,选择“添加”按钮。On the External Tools dialog box, choose the Add button. 随即出现一个新项。A new entry appears.

  5. 为新菜单项输入“标题”,例如 Command PromptEnter a Title for your new menu item such as Command Prompt.

  6. 在“命令”字段中,指定要启动的文件,例如 %comspec%C:\Windows\System32\cmd.exeIn the Command field, specify the file you want to launch, such as %comspec% or C:\Windows\System32\cmd.exe.

  7. 在“参数”字段中,指定可在其中找到要使用的特定命令提示的位置,例如 /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"In the Arguments field, specify where to find the specific command prompt you want to use, such as /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat". 此命令将启动随 Visual Studio 2019 Community 一起安装的开发人员命令提示。This command launches the Developer Command Prompt that's installed with Visual Studio 2019 Community. 根据 Visual Studio 版本和安装位置更改此值。Change this value according to your Visual Studio version, edition, and installation location.

  8. 在“初始目录”字段中,指定将在其中启动命令提示符的目录。In the Initial directory field, specify the directory in which the command prompt will start. 通过选择字段旁边的箭头选择值(如“项目目录”)。Choose a value such as Project Directory by selecting the arrow next to the field.

  9. 选择“确定” 按钮。Choose the OK button.

    已填写字段值的“外部工具”对话框。

    系统添加了新菜单项,并且你可以从“工具”菜单访问命令提示符。The new menu item is added, and you can access the command prompt from the Tools menu.

    Visual Studio 中的命令提示符菜单项

请参阅See also