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.NET,或 Visual Studio Enterprise 的 Snapshot DebuggerRemote debug ASP.NET on Azure or, for Visual Studio Enterprise, the Snapshot Debugger
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. 下载与设备操作系统(x86、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. 下载与设备操作系统(x86、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. 下载与设备操作系统(x86、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 文档For 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.

备注

  • 若要在 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 SystemsSupported Operating Systems

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

  • Windows 10(非手机版)Windows 10 (not phone)

  • Windows 8 或 8.1(非手机版)Windows 8 or 8.1 (not phone)

  • Windows 7 Service Pack 1Windows 7 Service Pack 1

  • Windows 2016 ServerWindows 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

备注

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

可以在已安装 Visual Studio Community、Professional 或 Enterprise 的计算机上找到远程调试器 (msvsmon.exe)。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. 在与你的 Visual Studio 版本匹配的目录中找到 msvsmon.exe: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 计算机上共享“Remote Debugger”文件夹。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.

提示

有关命令行安装和命令行参考,请参阅 msvsmon.exe 的“帮助”页,方法是在安装了 Visual Studio 的计算机上的命令行中键入 msvsmon.exe /?(或转到远程调试器中的“帮助”>“使用情况”)。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.

    重要

    可以在其他用户帐户(不同于你在 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 <username> 参数的命令行启动远程调试器: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.

    有关默认使用的端口号的列表,请参阅远程调试器端口分配For a listing of the port numbers used by default, see Remote Debugger Port Assignments.

    警告

    可以选择在“无身份验证”模式下运行远程工具,但强烈建议不要使用此模式。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