在 Visual Studio 中调试已安装的 UWP 应用包Debug an installed UWP app package in Visual Studio

Visual Studio 可以调试 Windows 10 计算机以及 Xbox、HoloLens 和 IoT 设备上已安装的通用 Windows 平台 (UWP) 应用包。Visual Studio can debug installed Universal Windows Platform (UWP) app packages on Windows 10 computers and Xbox, HoloLens, and IoT devices.

备注

手机不支持 Visual Studio 调试已安装的 UWP 应用。Visual Studio debugging for installed UWP apps is not supported on phones.

有关调试 UWP 应用的详细信息,请参阅有关调试安装的应用包生成通用 Windows 应用 (UWP) 的博客文章。For more information about debugging UWP apps, see the blog posts on debugging installed app packages and building Universal Windows Apps (UWP).

在本地计算机上调试已安装的 UWP 应用Debug an installed UWP app on a local machine

  1. 在 Visual Studio 中,选择“调试” > “其他调试目标” > “调试安装的应用程序包”。In Visual Studio, select Debug > Other Debug Targets > Debug Installed App Package.

  2. 在“调试已安装的应用包”对话框的“连接类型”下,选择“本地计算机”。In the Debug Installed App Package dialog, under Connection Type, select Local Machine.

  3. 在“已安装的应用包”下选择要调试的应用,或在搜索框中键入其名称。Under Installed App Packages, select the app you want to debug, or type its name in the search box. 未运行的已安装应用包显示在“未运行”下,正在运行的应用显示在“正在运行”下。Non-running installed app packages appear under Not running, and running apps are under Running.

    DebugInstalledAppPackageDebugInstalledAppPackage

  4. 如有必要,更改“调试此代码类型”下的代码类型,然后选择其他选项。If necessary, change the code type under Debug this code type, and select other options.

    • 选择“不启动,但在启动时调试我的代码”,在应用启动时开始调试。Select Do not launch, but debug my code when it starts to start debugging when the app starts. 应用启动时开始调试是调试来自不同启动方法(例如使用自定义参数激活协议)的控制路径的有效方法。Starting debugging when the app launches is an effective way to debug control paths from different launch methods, such as protocol activation with custom parameters.
  5. 选择“开始”,或如果应用正在运行,则选择“附加”。Select Start, or if the app is running, select Attach.

备注

此外,还可以通过在 Visual Studio 中选择“调试” > “附加到进程”以附加到任何正在运行的 UWP 或其他应用进程。You can also attach to any running UWP or other app process by selecting Debug > Attach to Process in Visual Studio. 无需原始 Visual Studio 项目也可附加到正在运行的进程中,但是在调试你没有原始代码的进程时,加载应用的符号会有很大帮助。You don't need the original Visual Studio project to attach to a running process, but loading the app's symbols will help significantly when debugging a process that you don't have the original code for. 请参阅在调试器中指定符号和源文件See Specify symbol and source files in the debugger.

在远程计算机或设备上调试已安装的 UWP 应用Debug an installed UWP app on a remote computer or device

Visual Studio 首次调试 Windows 10 设备或后创意者更新 Windows 10 远程计算机上已安装的 UWP 应用时,会在目标设备上安装远程调试工具。The first time Visual Studio debugs an installed UWP app on a Windows 10 device or a remote post-Creator's Update Windows 10 computer, it installs the remote debugging tools on the target device.

  1. 在 Visual Studio 计算机和远程设备/计算机上启用开发人员模式Enable developer mode on the Visual Studio computer and the remote device or computer.

  2. 如果要连接到运行预创意者更新 Windows 10 的远程计算机,请在该远程计算机上手动安装并启动远程调试器If you are connecting to a remote computer running pre-Creator's Update Windows 10, manually install and start the remote debugger on the remote computer.

  3. 在 Visual Studio 计算机上,选择“调试” > “其他调试目标” > “调试已安装的应用包”。On the Visual Studio computer, select Debug > Other Debug Targets > Debug Installed App Package.

  4. 在“调试已安装的应用包”对话框的“连接类型”下,选择“远程计算机”或“设备”。In the Debug Installed App Package dialog, under Connection Type, select Remote Machine or Device.

    如果选择“设备”,则计算机必须以物理方式连接到 Windows 10 设备。If you select Device, your computer must be physically connected to a Windows 10 device.

    对于远程计算机,如果计算机地址未出现在“地址”旁,请选择“更改”。For a remote machine, if the computer address doesn't appear next to Address, select Change.

    1. 在“远程连接”对话框中,在“地址”旁键入要连接到的计算机的名称或 IP 地址。In the Remote Connection dialog box, next to Address, type the name or IP address of the computer you want to connect to.

      ChooseRemoteComputerChooseRemoteComputer

      如果调试器无法使用计算机名称连接到远程计算机,请改用 IP 地址。If the debugger can't connect to a remote computer using the computer name, use the IP address instead. 对 Xbox、HoloLens 或 IoT 设备使用 IP 地址。Use the IP address for Xbox, HoloLens, or IoT devices.

    2. 在“身份验证模式”旁选择身份验证选项。Select an authentication option next to Authentication Mode.

      对于大多数应用,保留默认值“通用(未加密协议)”。For most apps, keep the default value, Universal (Unencrypted Protocol).

    3. 选择“选择”。Select Select.

  5. 在“已安装的应用包”下选择要调试的应用,或在搜索框中键入其名称。Under Installed App Packages, select the app you want to debug, or type its name in the search box. 未运行的已安装应用包显示在“未运行”下,正在运行的应用显示在“正在运行”下。Non-running installed app packages appear under Not running, and running apps are under Running.

  6. 如有必要,更改“调试此代码类型”下的代码类型,然后选择其他选项。If necessary, change the code type under Debug this code type, and select other options.

    • 选择“不启动,但在启动时调试我的代码”,在应用启动时开始调试。Select Do not launch, but debug my code when it starts to start debugging when the app starts. 应用启动时开始调试是调试来自不同启动方法(例如使用自定义参数激活协议)的控制路径的有效方法。Starting debugging when the app launches is an effective way to debug control paths from different launch methods, such as protocol activation with custom parameters.
  7. 选择“开始”,或如果应用正在运行,则选择“附加”。Select Start, or if the app is running, select Attach.

首次开始调试已连接的 Xbox、HoloLens 或 IoT 设备上已安装的应用包时,Visual Studio 会对目标设备安装正确版本的远程调试器。When you start debugging an installed app package on a connected Xbox, HoloLens, or IoT device for the first time, Visual Studio installs the correct version of the remote debugger for your target device. 安装远程调试器可能需要一些时间,并且在安装过程中会显示“正在启动远程调试器”消息。Installing the remote debugger may take some time, and the message Starting remote debugger displays while it is happening.

备注

目前,Xbox 或 HoloLens 设备附加调试器时,如果已运行则重启应用。Currently, an Xbox or HoloLens device restarts the app with the debugger attached if it was already running.

对于UWP 应用远程部署的更多信息,请参阅部署和调试 UWP 应用远程计算机上的调试 UWP 应用For more information on remote deployment of UWP apps, see Deploy and debug UWP apps and Debug UWP apps on remote machines.

请参阅See also