Remote DebuggingRemote Debugging

你可以调试已部署在另一台计算机的 Visual Studio 应用程序。You can debug a Visual Studio application that has been deployed on a different computer. 要进行此操作,可使用 Visual Studio 远程调试器。To do so, you use the Visual Studio remote debugger.

有关远程调试的深入说明,请参阅以下主题。For in-depth instructions on remote debugging, see these topics.

方案Scenario 链接Link
Azure 应用服务Azure App Service 快照调试器远程调试 Azure 上的 ASP.NETSnapshot Debugger or Remote debug ASP.NET on Azure
Azure VMAzure VM 远程调试 Azure 上的 ASP.NETRemote debug ASP.NET on Azure
Azure Service FabricAzure Service Fabric 调试 Azure Service Fabric 应用程序Debug an Azure Service Fabric application
ASP.NETASP.NET 远程调试 ASP.NET Core远程调试 ASP.NETRemote debug ASP.NET Core or Remote Debug ASP.NET
C# 或 Visual BasicC# or Visual Basic 远程调试 C# 或 Visual Basic 项目Remote debug a C# or Visual Basic project
C++C++ 远程调试 C++ 项目Remote debug a C++ project
通用 Windows 应用 (UWP)Universal Windows Apps (UWP) 在远程计算机上运行 UWP 应用调试安装的应用包Run UWP apps on a remote machine or Debug an installed app package

如果只是想要下载并安装远程调试器,并且不需要任何其他说明为你的方案,请按照本文中的步骤。If you just want to download and install the remote debugger and don't need any additional instructions for your scenario, follow the steps in this article.

下载和安装远程工具Download and Install the remote tools

在远程设备或服务器,你想要调试,而非 Visual Studio 计算机,下载并安装远程工具的正确版本从下表中的链接。On the remote device or server that you want to debug on, rather than the Visual Studio machine, download and install the correct version of the remote tools from the links in the following table.

  • 下载最新版本的 Visual Studio 远程工具。Download the most recent remote tools for your version of Visual Studio. 最新的远程工具版本兼容使用早期的 Visual Studio 版本,但早期的远程工具版本不是与更高版本的 Visual Studio 版本兼容。The latest remote tools version is compatible with earlier Visual Studio versions, but earlier remote tools versions aren't compatible with later Visual Studio versions. (例如,如果使用 Visual Studio 2017,下载适用于 Visual Studio 2017 远程工具的最新的更新。(For example, if you are using Visual Studio 2017, download the latest update of the remote tools for Visual Studio 2017. 在此方案中,不要下载远程工具的 Visual Studio 2019。)In this scenario, do not download the remote tools for Visual Studio 2019.)
  • 下载的远程工具使用相同的体系结构在计算机安装它们。Download the remote tools with the same architecture as the machine you're installing them on. 例如,如果你想要调试远程计算机运行 64 位操作系统上的 32 位应用程序,安装 64 位远程工具。For example, if you want to debug a 32-bit app on a remote computer running a 64-bit operating system, install the 64-bit remote tools.
VersionVersion 链接Link 说明Notes
Visual Studio 2019Visual Studio 2019 远程工具Remote tools 与所有 Visual Studio 2019 版本兼容。Compatible with all Visual Studio 2019 versions. 下载匹配您设备的操作系统 (x 86、 x64、 或 ARM64) 的版本。Download the version matching your device operating system (x86, x64, or ARM64). 在 Windows 服务器上,请参阅取消阻止文件下载下载远程工具的帮助。On Windows Server, see Unblock the file download for help downloading the remote tools.
Visual Studio 2017Visual Studio 2017 远程工具Remote tools 与所有 Visual Studio 2017 版本兼容。Compatible with all Visual Studio 2017 versions. 下载匹配您设备的操作系统 (x 86、 x64、 或 ARM64) 的版本。Download the version matching your device operating system (x86, x64, or ARM64). 在 Windows 服务器上,请参阅取消阻止文件下载下载远程工具的帮助。On Windows Server, see Unblock the file download for help downloading the remote tools.
Visual Studio 2015Visual Studio 2015 远程工具Remote tools Visual Studio 2015 远程工具可从 My.VisualStudio.com。Remote tools for Visual Studio 2015 are available from My.VisualStudio.com. 如果系统提示,请加入免费Visual Studio Dev Essentials程序或使用 Visual Studio 订阅 id。 登录If prompted, join the free Visual Studio Dev Essentials program, or sign in with your Visual Studio subscription ID. 在 Windows 服务器上,请参阅取消阻止文件下载下载远程工具的帮助。On Windows Server, see Unblock the file download for help downloading the remote tools.
Visual Studio 2013Visual Studio 2013 远程工具Remote tools 下载 Visual Studio 2013 文档中的页Download page in Visual Studio 2013 documentation
Visual Studio 2012Visual Studio 2012 远程工具Remote tools 下载 Visual Studio 2012 文档中的页Download page in Visual Studio 2012 documentation
VersionVersion 链接Link 说明Notes
Visual Studio 2017Visual Studio 2017 远程工具Remote tools 与所有 Visual Studio 2017 版本兼容。Compatible with all Visual Studio 2017 versions. 下载匹配您设备的操作系统 (x 86、 x64、 或 ARM64) 的版本。Download the version matching your device operating system (x86, x64, or ARM64). 在 Windows 服务器上,请参阅取消阻止文件下载下载远程工具的帮助。On Windows Server, see Unblock the file download for help downloading the remote tools. 有关远程工具的最新版本,打开Visual Studio 2019 docFor the most recent version of the remote tools, open the Visual Studio 2019 doc.
Visual Studio 2015Visual Studio 2015 远程工具Remote tools Visual Studio 2015 远程工具可从 My.VisualStudio.com。Remote tools for Visual Studio 2015 are available from My.VisualStudio.com. 如果系统提示,请加入免费Visual Studio Dev Essentials程序或使用 Visual Studio 订阅 id。 登录If prompted, join the free Visual Studio Dev Essentials program, or sign in with your Visual Studio subscription ID. 在 Windows 服务器上,请参阅取消阻止文件下载下载远程工具的帮助。On Windows Server, see Unblock the file download for help downloading the remote tools.
Visual Studio 2013Visual Studio 2013 远程工具Remote tools 下载 Visual Studio 2013 文档中的页Download page in Visual Studio 2013 documentation
Visual Studio 2012Visual Studio 2012 远程工具Remote tools 下载 Visual Studio 2012 文档中的页Download page in Visual Studio 2012 documentation

复制可运行远程调试器msvsmon.exe到远程计算机,而不是安装远程工具。You can run the remote debugger by copying msvsmon.exe to the remote computer, rather than installing the remote tools. 但是,远程调试器配置向导 (rdbgwiz.exe) 可仅当安装远程工具。However, the Remote Debugger Configuration Wizard (rdbgwiz.exe) is available only when you install the remote tools. 您可能需要使用该向导进行配置,如果你想要远程调试器作为服务运行。You may need to use the wizard for configuration if you want to run the remote debugger as a service. 有关详细信息,请参阅(可选) 配置远程调试器作为服务For more information, see (Optional) Configure the remote debugger as a service.

Note

  • 若要调试 ARM 设备上的 Windows 10 应用,使用 ARM64,这是可用的远程工具的最新版本。To debug Windows 10 apps on ARM devices, use ARM64, which is available with the latest version of the remote tools.
  • 若要调试在 Windows RT 设备上的 Windows 10 应用,使用 ARM,仅在 Visual Studio 2015 远程工具下载中可用。To debug Windows 10 apps on Windows RT devices, use ARM, which is available only in the Visual Studio 2015 remote tools download.

要求Requirements

支持的操作系统Supported Operating Systems

远程计算机运行的是下列操作系统之一:The remote computer must be running one of the following operating systems:

  • Windows 10 (而不是 phone)Windows 10 (not phone)

  • Windows 8 或 8.1 (而不是 phone)Windows 8 or 8.1 (not phone)

  • Windows 7 Service Pack 1Windows 7 Service Pack 1

  • Windows Server 2016Windows Server 2016

  • Windows Server 2012 或 Windows Server 2012 R2Windows Server 2012 or Windows Server 2012 R2

  • Windows Server 2008 Service Pack 2、Windows Server 2008 R2 Service Pack 1Windows Server 2008 Service Pack 2, Windows Server 2008 R2 Service Pack 1

Note

Windows Phone 需要通过 USB 连接调试 (不需要远程工具)。Windows Phone requires a USB connection to debug (it does not require the remote tools).

支持的硬件配置Supported Hardware Configurations

  • 1.6 GHz 或更快的处理器1.6 GHz or faster processor

  • 1 GB 的 RAM(如果在虚拟机上运行则需 1.5 GB)1 GB of RAM (1.5 GB if running on a virtual machine)

  • 1 GB 的可用硬盘空间1 GB of available hard disk space

  • 5400 RPM 硬盘驱动器5400-RPM hard drive

  • DirectX 9 支持的视频卡,可在 1024 x 768 或更高版本的显示分辨率下运行DirectX 9-capable video card running at 1024 x 768 or higher display resolution

网络配置Network configuration

远程计算机与 Visual Studio 计算机必须通过网络、工作组、家庭组或其他通过以太网电缆直接连接的方式连接在一起。The remote computer and the Visual Studio computer must be connected over a network, workgroup, or homegroup, or else connected directly through an Ethernet cable. 不支持调试通过代理连接的两台计算机之间。Debugging between two computers connected through a proxy is not supported. 调试通过高延迟或低带宽连接,例如拨号 Internet,或通过 Internet 跨国家/地区不建议并可能会失败或很令人无法接受慢。Debugging over a high latency or low bandwidth connection, such as dialup Internet, or over the Internet across countries is not recommended and may fail or be unacceptably slow.

(可选)若要从文件共享运行远程调试器(Optional) To run the remote debugger from a file share

您可以找到远程调试器 (msvsmon.exe) 使用 Visual Studio Community、 Professional 或 Enterprise 已安装的计算机上。You can find the remote debugger (msvsmon.exe) on a computer with Visual Studio Community, Professional, or Enterprise already installed. 在某些情况下,设置远程调试的最简单方法是从文件共享运行远程调试器 (msvsmon.exe)。For some scenarios, the easiest way to set up remote debugging is to run the remote debugger (msvsmon.exe) from a file share. 有关使用情况的限制,请参阅远程调试器的帮助页 (帮助 > 用法远程调试器中)。For usage limitations, see the remote debugger's Help page (Help > Usage in the remote debugger).

  1. 查找msvsmon.exe匹配你的 Visual Studio 版本的目录中:Find msvsmon.exe in the directory matching your version of Visual Studio:

    Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Remote Debugger\x86\msvsmon.exeProgram Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Remote Debugger\x86\msvsmon.exe

    Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Remote Debugger\x64\msvsmon.exeProgram Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Remote Debugger\x64\msvsmon.exe

    程序文件 (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x86\msvsmon.exeProgram Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x86\msvsmon.exe

    程序文件 (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x64\msvsmon.exeProgram Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x64\msvsmon.exe

  2. 共享远程调试器Visual Studio 计算机上的文件夹。Share the Remote Debugger folder on the Visual Studio computer.

  3. 在远程计算机上运行msvsmon.exe从共享文件夹。On the remote computer, run msvsmon.exe from the shared folder. 请按照安装说明进行操作Follow the setup instructions.

Tip

命令行安装和命令行参考,请参阅的帮助页msvsmon.exe通过键入msvsmon.exe /?在安装了 Visual studio 计算机上的命令行中 (或转到帮助 > 用法远程调试器中)。For command line installation and command line reference, see the Help page for msvsmon.exe by typing msvsmon.exe /? in the command line on the computer with Visual Studio installed (or go to Help > Usage in the remote debugger).

设置远程调试器Set up the remote debugger

  1. 在远程计算机上查找和启动远程调试器启动菜单。On the remote computer, find and start the Remote Debugger from the Start menu.

    如果在远程计算机上没有管理权限,请右击远程调试器应用,然后选择以管理员身份运行If you don't have administrative permissions on the remote computer, right-click the Remote Debugger app and select Run as administrator. 否则,只是它正常启动。Otherwise, just start it normally.

    如果想要附加到正在运行以管理员身份,或不同的用户下运行的进程帐户 (如 IIS) 中,右键单击远程调试器应用,然后选择以管理员身份运行.If you are planning to attach to a process which is running as an administrator, or is running under a different user account (such as IIS), right-click the Remote Debugger app and select Run as administrator. 有关详细信息,请参阅以管理员身份运行远程调试器For more information, see Run the remote debugger as an administrator.

  2. 第一次启动远程调试器 (或之前已配置),远程调试配置对话框随即出现。The first time you start the remote debugger (or before you have configured it), the Remote Debugging Configuration dialog box appears.

    远程调试器配置Remote Debugger configuration

  3. 如果 Windows Web 服务 API 未安装,这种情况发生,仅在 Windows Server 2008 R2 上,选择安装按钮。If the Windows Web Services API is not installed, which happens only on Windows Server 2008 R2, select the Install button.

  4. 选择你想要在使用远程工具的至少一个网络类型。Select at least one network type you want to use the remote tools on. 如果这些计算机通过域连接,则必须选择第一项。If the computers are connected through a domain, you must choose the first item. 如果这些计算机通过工作组或家庭组连接,选择相应的第二个或第三个项。If the computers are connected through a workgroup or homegroup, choose the second or third item as appropriate.

  5. 选择配置远程调试,配置防火墙并启动远程调试器。Select Configure remote debugging to configure the firewall and start the remote debugger.

  6. 配置完成后,远程调试器窗口会显示。When configuration is complete, the Remote Debugger window appears.

    远程调试器窗口Remote Debugger window

    远程调试器现在正在等待连接。The remote debugger is now waiting for a connection. 使用服务器名称和端口号显示在 Visual Studio 中设置的远程连接配置。Use the server name and port number shown to set the remote connection configuration in Visual Studio.

若要停止远程调试器,请选择文件 > 退出To stop the remote debugger, select File > Exit. 您可以重新启动它从启动菜单中,或从命令行:You can restart it from the Start menu, or from the command line:

<Remote debugger installation directory>\msvsmon.exe

配置远程调试器Configure the remote debugger

首次启动后,你可以更改远程调试器的部分配置。You can change some aspects of the configuration of the remote debugger after you have started it for the first time.

  • 如果你需要为连接到远程调试器,请选择其他用户添加权限工具 > 权限If you need to add permissions for other users to connect to the remote debugger, choose Tools > Permissions. 你必须拥有管理员特权才能授予或拒绝权限。You must have administrator privileges to grant or deny permissions.

    Important

    您可以从 Visual Studio 计算机所使用的用户帐户运行远程调试器在不同的用户帐户下,但必须将其他用户帐户添加到远程调试器的权限。You can run the remote debugger under a user account that differs from the user account you are using on the Visual Studio computer, but you must add the different user account to the remote debugger's permissions.

    或者,可以从命令行启动远程调试器 /allow<用户名 > 参数: msvsmon /allow < username@computer>Alternatively, you can start the remote debugger from the command line with the /allow <username> parameter: msvsmon /allow <username@computer>.

  • 如果你需要更改身份验证模式或端口号,或指定的远程工具的超时值: 选择工具 > 选项If you need to change the Authentication mode or the port number, or specify a timeout value for the remote tools: choose Tools > Options.

    默认情况下使用的端口号的列表,请参阅Remote Debugger Port AssignmentsFor a listing of the port numbers used by default, see Remote Debugger Port Assignments.

    Warning

    可以选择在“无身份验证”模式下运行远程工具,但强烈建议不要使用此模式。You can choose to run the remote tools in No Authentication mode, but this mode is strongly discouraged. 在此模式下运行时,无法保证网络安全。There is no network security when you run in this mode. 只有在确认网络不会遇到恶意通信的情况下,才可选择“无身份验证”模式。Choose the No Authentication mode only if you are sure that the network is not at risk from malicious or hostile traffic.

(可选)配置远程调试器作为服务(Optional) Configure the remote debugger as a service

用于调试 ASP.NET 和其他服务器环境中,您必须以管理员身份运行远程调试器或时,如果希望始终运行,作为服务运行远程调试器。For debugging in ASP.NET and other server environments, you must either run the remote debugger as an Administrator or, if you want it always running, run the remote debugger as a service.

如果你想要配置远程调试器作为服务,请按照下列步骤。If you want to configure the remote debugger as a service, follow these steps.

  1. 找到 “远程调试器配置向导”(rdbgwiz.exe)。Find the Remote Debugger Configuration Wizard (rdbgwiz.exe). (这是独立于远程调试器的应用程序。)仅在你安装远程工具后,它才可用。(This is a separate application from the Remote Debugger.) It is available only when you install the remote tools. 它不与 Visual Studio 一起安装。It is not installed with Visual Studio.

  2. 开始运行配置向导。Start running the configuration wizard. 当第一页出现时,单击“下一步” 。When the first page comes up, click Next.

  3. 勾选“将 Visual Studio 2015 远程调试器作为服务运行” 复选框。Check the Run the Visual Studio 2015 Remote Debugger as a service checkbox.

  4. 添加用户帐户的名称和密码。Add the name of the user account and password.

    可能需要添加作为服务登录右到此帐户的用户 (查找本地安全策略(secpol.msc) 中启动页或窗口 (或类型secpol在命令提示符下)。You may need to add the Log on as a service user right to this account (Find Local Security Policy (secpol.msc) in the Start page or window (or type secpol at a command prompt). 当显示窗口时,双击“用户权限分配” ,然后在右窗格中找到 “作为服务登录”。When the window appears, double-click User Rights Assignment, then find Log on as a service in the right pane. 双击该选项。Double-click it. 将用户帐户添加到“属性”窗口,然后点击“确定”) 。Add the user account to the Properties window and click OK). 单击 “下一步”Click Next.

  5. 选择你希望远程工具与之通信的网络类型。Select the type of network that you want the remote tools to communicate with. 必须至少选择一种网络类型。At least one network type must be selected. 如果这些计算机通过域连接,则应选择第一项。If the computers are connected through a domain, you should choose the first item. 如果这些计算机通过工作组或家庭组连接,则应选择第二或第三项。If the computers are connected through a workgroup or homegroup, you should choose the second or third items. 单击 “下一步”Click Next.

  6. 如果可以启动服务,则会显示 “你已成功完成 Visual Studio 远程调试器配置向导”。If the service can be started, you will see You have successfully completed the Visual Studio Remote Debugger Configuration Wizard. 如果无法启动服务,则会显示“未能完成 Visual Studio 远程调试器配置向导” 。If the service cannot be started, you will see Failed to complete the Visual Studio Remote Debugger Configuration Wizard. 此页还提供了为使服务正常启动要遵循的一些提示。The page also gives some tips to follow to get the service to start.

  7. 单击 “完成”Click Finish.

    此时,远程调试器正作为服务运行。At this point the remote debugger is running as a service. 可以通过转到“控制面板”>“服务”并找到 “Visual Studio 2015 远程调试器”来对此进行验证 。You can verify this by going to Control Panel > Services and looking for Visual Studio 2015 Remote Debugger.

    可以从“控制面板”>“服务”停止和启动远程调试器服务 。You can stop and start the remote debugger service from Control Panel > Services.

设置使用远程符号进行调试Set up debugging with remote symbols

你应能够使用你在 Visual Studio 计算机生成的符号调试你的代码。You should be able to debug your code with the symbols you generate on the Visual Studio computer. 使用本地符号时远程调试器的性能更佳。The performance of the remote debugger is much better when you use local symbols. 如果必须使用远程符号,则需要告诉远程调试监视器以查找远程计算机上的符号。If you must use remote symbols, you need to tell the remote debugging monitor to look for symbols on the remote machine.

从 Visual Studio 2013 Update 2 开始,你可以使用以下 msvsmon 命令行开关来使用用于托管代码的远程符号:Msvsmon /FallbackLoadRemoteManagedPdbsStarting in Visual Studio 2013 Update 2, you can use the following msvsmon command-line switch to use remote symbols for managed code: Msvsmon /FallbackLoadRemoteManagedPdbs

有关详细信息,请参阅远程调试帮助(在远程调试器窗口中,按 F1 或依次单击“帮助”>“用法”)。For more information, please see the remote debugging help (press F1 in the remote debugger window, or click Help > Usage). 有关详细信息,可以参阅 Visual Studio 2012 和 2013 中的 .NET 远程符号加载更改You can find more information at .NET Remote Symbol Loading Changes in Visual Studio 2012 and 2013

请参阅See also