在 Visual Studio 中远程调试远程 IIS 计算机上的 ASP.NET CoreRemote Debug ASP.NET Core on a Remote IIS Computer in Visual Studio

05/06/2020

本文内容

若要调试已部署到 IIS 的 ASP.NET Core 应用程序,请在部署应用的计算机上安装并运行远程工具,然后从 Visual Studio 附加到正在运行的应用。To debug an ASP.NET Core application that has been deployed to IIS, install and run the remote tools on the computer where you deployed your app, and then attach to your running app from Visual Studio.

本指南说明如何设置和配置 Visual Studio ASP.NET Core,将其部署到 IIS,并从 Visual Studio 附加远程调试器。This guide explains how to set up and configure a Visual Studio ASP.NET Core, deploy it to IIS, and attach the remote debugger from Visual Studio. 若要远程调试 ASP.NET 4.5.2,请参阅远程调试 IIS 计算机上的 ASP.NET。也可以使用 Azure 在 IIS 上进行部署和调试。You can also deploy and debug on IIS using Azure. 对于 Azure 应用服务,可以使用 Snapshot Debugger 或通过从服务器资源管理器附加调试器,在预先配置的 IIS 实例和远程调试器上轻松进行部署和调试。For Azure App Service, you can easily deploy and debug on a preconfigured instance of IIS and the remote debugger using either the Snapshot Debugger or by attaching the debugger from Server Explorer.

先决条件Prerequisites

需要安装 Visual Studio 2019 才能执行本文所述的步骤。Visual Studio 2019 is required to follow the steps shown in this article.

需要安装 Visual Studio 2017 才能执行本文所述的步骤。Visual Studio 2017 is required to follow the steps shown in this article.

这些过程已在以下服务器配置上进行了测试:These procedures have been tested on these server configurations:

Windows Server 2012 R2 和 IIS 8Windows Server 2012 R2 and IIS 8

Windows Server 2016 和 IIS 10Windows Server 2016 and IIS 10

Windows Server 2019 和 IIS 10Windows Server 2019 and IIS 10

网络要求Network requirements

不支持在通过代理连接的两台计算机之间进行调试。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. 有关要求的完整列表,请参阅要求。For a complete list of requirements, see Requirements.

应用已在 IIS 中运行?App already running in IIS?

本文包含有关在 Windows Server 上设置 IIS 的基本配置以及从 Visual Studio 部署应用的步骤。This article includes steps on setting up a basic configuration of IIS on Windows server and deploying the app from Visual Studio. 这些步骤可确保服务器安装了必需的组件,应用可以正常运行,以及你已经准备好进行远程调试。These steps are included to make sure that the server has required components installed, that the app can run correctly, and that you are ready to remote debug.

如果应用正在 IIS 中运行,你只想下载远程调试器并启动调试,请转到在 Windows Server 上下载并安装远程工具。If your app is running in IIS and you just want to download the remote debugger and start debugging, go to Download and Install the remote tools on Windows Server.

如果需要帮助确保在 IIS 中正确设置、部署和运行应用,以便进行调试,请按照本主题中的所有步骤进行操作。If you want help to make sure that your app is set up, deployed, and running correctly in IIS so that you can debug, follow all the steps in this topic.

在 Visual Studio 计算机上创建 ASP.NET Core 应用程序Create the ASP.NET Core application on the Visual Studio computer

创建新的 ASP.NET Core Web 应用呈现。Create a new ASP.NET Core web application.

在 Visual Studio 2019 中,键入 Ctrl + Q 打开搜索框,键入“asp.net”,选择“模板”,然后选择“创建新的 ASP.NET Core Web 应用程序” 。In Visual Studio 2019, type Ctrl + Q to open the search box, type asp.net, choose Templates, then choose Create new ASP.NET Core Web Application. 在出现的对话框中,将项目命名为“MyASPApp”,然后选择“创建” 。In the dialog box that appears, name the project MyASPApp, and then choose Create. 接下来,选择“Web 应用程序(模型-视图-控制器)”,然后选择“创建” 。Next, choose Web Application (Model-View-Controller), and then choose Create.

在 Visual Studio 2017 中,选择“文件”>“新建”>“项目”,然后选择“Visual C#”>“Web”>“ASP.NET Core Web 应用程序” 。In Visual Studio 2017, choose File > New > Project, then select Visual C# > Web > ASP.NET Core Web Application. 在“ASP.NET Core 模板”部分中,选择“Web 应用程序(模型-视图-控制器)”。In the ASP.NET Core templates section, select Web Application (Model-View-Controller). 确保选择了 ASP.NET Core 2.1,未选择“启用 Docker 支持”,并且“身份验证”设置为“无身份验证” 。Make sure that ASP.NET Core 2.1 is selected, that Enable Docker Support is not selected and that Authentication is set to No Authentication. 将项目命名为“MyASPApp”。Name the project MyASPApp.

打开 About.cshtml.cs 文件,并在 OnGet 方法中设置断点(在较旧的模板中,改为打开 HomeController.cs 并在 About() 方法中设置断点)。Open the About.cshtml.cs file and set a breakpoint in the OnGet method (in older templates, open HomeController.cs instead and set the breakpoint in the About() method).

在 Windows Server 上安装和配置 IISInstall and Configure IIS on Windows Server

以下步骤仅显示 IIS 的基本配置。These steps show only a basic configuration of IIS. For more in-depth information or to install to a Windows Desktop machine, see Publishing to IIS or IIS 8.0 Using ASP.NET 3.5 and ASP.NET 4.5.

对于 Windows Server 操作系统,通过“管理”链接或“服务器管理器”中的“仪表板”链接使用“添加角色和功能”向导 。For Windows Server operating systems, use the Add Roles and Features wizard via the Manage link or the Dashboard link in Server Manager. 在“服务器角色”步骤中,选中“Web 服务器(IIS)”框 。On the Server Roles step, check the box for Web Server (IIS).

在“角色服务”步骤中,选择所需 IIS 角色服务,或接受提供的默认角色服务 。On the Role services step, select the IIS role services you desire or accept the default role services provided. 如果要使用发布设置和 Web 部署启用部署,请确保选中“IIS 管理脚本和工具” 。If you want to enable deployment using publish settings and Web Deploy, make sure that IIS Management Scripts and Tools is selected.

继续执行确认步骤,安装 Web 服务器角色和服务。Proceed through the confirmation steps to install the web server role and services. 安装 Web 服务器 (IIS) 角色后无需重启服务器/IIS。A server/IIS restart is not required after installing the Web Server (IIS) role.

更新 Windows Server 上的浏览器安全设置Update browser security settings on Windows Server

如果在 Internet Explorer 中启用了“增强的安全配置”(默认情况下已启用),则可能需要将某些域添加为受信任的站点,以便下载某些 Web 服务器组件。If Enhanced Security Configuration is enabled in Internet Explorer (it is enabled by default), then you may need to add some domains as trusted sites to enable you to download some of the web server components. 通过转到“Internet 选项”>“安全性”>“受信任的站点”>“站点”来添加受信任的站点。Add the trusted sites by going to Internet Options > Security > Trusted Sites > Sites. 添加以下域。Add the following domains.

microsoft.commicrosoft.com

go.microsoft.comgo.microsoft.com

download.microsoft.comdownload.microsoft.com

iis.netiis.net

下载软件时,可能会收到授权加载各种网站脚本和资源的请求。When you download the software, you may get requests to grant permission to load various web site scripts and resources. 其中一些资源不是必需的,但为了简化此过程,请在出现提示时单击“添加”。Some of these resources are not required, but to simplify the process, click Add when prompted.

在 Windows Server 上安装 ASP.NET CoreInstall ASP.NET Core on Windows Server

在托管系统上安装 .NET Core 托管捆绑包。Install the .NET Core Hosting Bundle on the hosting system. 捆绑包可安装 .NET Core 运行时、.NET Core 库和 ASP.NET Core 模块。The bundle installs the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module. 有关更深入的说明,请参阅发布到 IIS。For more in-depth instructions, see Publishing to IIS.

备注

如果系统没有 Internet 连接,请先获取并安装 Microsoft Visual C++ 2015 Redistributable,再安装 .NET Core Windows Server 托管捆绑包。If the system doesn't have an Internet connection, obtain and install the

重启系统(或在命令提示符处依次执行“net stop was /y”和“net start w3svc”,了解系统路径的更改) 。Restart the system (or execute net stop was /y followed by net start w3svc from a command prompt to pick up a change to the system PATH).

选择部署选项Choose a deployment option

如果需要帮助将应用部署到 IIS,请考虑以下选项:If you need help to deploy the app to IIS, consider these options:

通过在 IIS 中创建发布设置文件并在 Visual Studio 中导入设置来进行部署。Deploy by creating a publish settings file in IIS and importing the settings in Visual Studio. 在某些情况下,这是一种快速部署应用的方法。In some scenarios, this is a fast way to deploy your app. 当你创建发布设置文件时,系统会在 IIS 中自动设置权限。When you create the publish settings file, permissions are automatically set up in IIS.

通过发布到本地文件夹并使用首选方法将输出复制到 IIS 上准备就绪的应用文件夹来进行部署。Deploy by publishing to a local folder and copying the output by a preferred method to a prepared app folder on IIS.

(可选)使用发布设置文件进行部署(Optional) Deploy using a publish settings file

可以使用此选项创建一个发布设置文件,并将其导入到 Visual Studio 中。You can use this option create a publish settings file and import it into Visual Studio.

备注

此部署方法使用 Web 部署,必须安装在服务器上。This deployment method uses Web Deploy, which must be installed on the server. 如果要手动配置 Web 部署,而不是导入设置,则可以安装 Web 部署 3.6,而不是用于托管服务器的 Web 部署 3.6。If you want to configure Web Deploy manually instead of importing the settings, you can install Web Deploy 3.6 instead of Web Deploy 3.6 for Hosting Servers. 但是,如果手动配置 Web 部署,则需要确保使用正确的值和权限配置服务器上的应用文件夹(请参阅配置 ASP.NET 网站)。However, if you configure Web Deploy manually, you will need to make sure that an app folder on the server is configured with the correct values and permissions (see Configure ASP.NET Web site).

配置 ASP.NET Core 网站Configure the ASP.NET Core web site

在 IIS 管理器左窗格的“连接”下,选择“应用程序池” 。In IIS Manager, in the left pane under Connections, select Application Pools. 打开 DefaultAppPool,将“.NET CLR 版本”设置为“无托管代码” 。Open DefaultAppPool and set the .NET CLR version to No Managed Code. ASP.NET Core 需要执行此操作。This is required for ASP.NET Core. 默认网站使用 DefaultAppPool。The Default Web Site uses the DefaultAppPool.

停止并重新启动 DefaultAppPool。Stop and restart the DefaultAppPool.

在 Windows Server 上安装和配置用于宿主服务器的 Web 部署Install and configure Web Deploy for Hosting Servers on Windows Server

用于托管服务器的 Web 部署 3.6 提供额外的配置功能,可实现从 UI 创建发布设置文件。Web Deploy 3.6 for Hosting Servers provides additional configuration features that enable the creation of the publish settings file from the UI.

如果已在 Windows Server 上安装 Web 部署,请使用“控制面板” > “程序” > “卸载程序”将其卸载。If you have Web Deploy already installed on Windows Server, uninstall it using Control Panel > Programs > Uninstall a Program.

接下来,在 Windows 服务器上安装用于托管服务器的 Web 部署 3.6。Next, install Web Deploy 3.6 for Hosting Servers on Windows Server.

要安装用于托管服务器的 Web 部署,请使用 Web 平台安装程序 (WebPI)。To install Web Deploy for Hosting Servers, use the Web Platform Installer (WebPI). (要从 IIS 查找 Web 平台安装程序链接,请选择服务器管理器左侧窗格中的“IIS”。(To find the Web Platform Installer link from IIS, select IIS in the left pane of Server Manager. 在服务器窗格中,右键单击服务器并选择“Internet Information Services (IIS)管理器”。In the server pane, right-click the server and select Internet Information Services (IIS) Manager. 然后,在“操作”窗口中,使用“获取新的 Web 平台组件”连接 。)你还可以从下载获取 Web 平台安装程序 (WebPI)。Then use the Get New Web Platform Components link in the Actions window.) You can also obtain the Web Platform Installer (WebPI) from downloads.

在 Web 平台安装程序中,在“应用程序”选项卡中查找“用于托管服务器的 Web 部署 3.6”。In the Web Platform Installer, you find Web Deploy 3.6 for Hosting Servers in the Applications tab.

如果尚未安装“IIS 管理脚本和工具”,请立即安装。If you did not already install IIS Management Scripts and Tools, install it now.

转到“选择服务器角色” > “Web 服务器(IIS)” > “管理工具”,然后选择“IIS 管理脚本和工具”角色,点击“下一步”,然后安装角色 。Go to Select server roles > Web Server (IIS) > Management Tools, and then select the IIS Management Scripts and Tools role, click Next, and then install the role.

需要脚本和工具来生成发布设置文件。The scripts and tools are required to enable the generation of the publish settings file.

根据需要,打开“控制面板”>“系统和安全”>“管理工具”>“服务”来验证 Web 部署是否正确运行,然后确保:(Optional) Verify that Web Deploy is running correctly by opening Control Panel > System and Security > Administrative Tools > Services, and then make sure that:

“Web 部署代理服务”正在运行(旧版本中的服务名称不同)。Web Deployment Agent Service is running (the service name is different in older versions).

“Web 管理服务”正在运行。Web Management Service is running.

如果某个代理服务未运行,请重新启动“Web 部署代理服务”。If one of the agent services is not running, restart the Web Deployment Agent Service.

如果 Web 部署代理服务不存在,请转到“控制面板”>“程序”>“卸载程序”,查找“Microsoft Web 部署 。If the Web Deployment Agent Service is not present at all, go to Control Panel > Programs > Uninstall a program, find Microsoft Web Deploy . 选择“更改”安装,并确保对 Web 部署组件选择“将安装到本地驱动器” 。Choose to Change the installation and make sure that you choose Will be installed to the local hard drive for the Web Deploy components. 完成更改安装步骤。Complete the change installation steps.

在 Windows Server 上的 IIS 中创建发布设置文件Create the publish settings file in IIS on Windows Server

关闭并重新打开 IIS 管理控制台以在 UI 中显示更新的配置选项。Close and reopen the IIS Management Console to show updated configuration options in the UI.

在 IIS 中,右键单击“默认网站”,选择“部署” > “配置 Web 部署发布” 。In IIS, right-click the Default Web Site, choose Deploy > Configure Web Deploy Publishing.

如果看不到“部署”菜单,请参阅前面的部分来验证 Web 部署是否正在运行。If you don't see the Deploy menu, see the preceding section to verify that Web Deploy is running.

在“配置 Web 部署发布”对话框中,检查设置。In the Configure Web Deploy Publishing dialog box, examine the settings.

单击“设置”。Click Setup.

在“结果”面板中,输出显示已为指定用户授予访问权限,并且已在对话框中显示的位置生成了具有 .publishsettings 文件扩展名的文件。In the Results panel, the output shows that access rights are granted to the specified user, and that a file with a .publishsettings file extension has been generated in the location shown in the dialog box.

publishUrl="https://myhostname:8172/msdeploy.axd"

msdeploySite="Default Web Site"

destinationAppUrl="http://myhostname:80/"

mySQLDBConnectionString=""

SQLServerDBConnectionString=""

profileName="Default Settings"

publishMethod="MSDeploy"

userName="myhostname\myusername" />

根据 Windows Server 和 IIS 配置,可以在 XML 文件看到不同的值。Depending on your Windows Server and IIS configuration, you see different values in the XML file. 下面是有关所看到的值的一些详细信息:Here are a few details about the values that you see:

publishUrl 属性中引用的 msdeploy.axd 文件是 Web 部署动态生成的 HTTP 处理程序文件。The msdeploy.axd file referenced in the publishUrl attribute is a dynamically generated HTTP handler file for Web Deploy. (用于测试目的,http://myhostname:8172 通常也适用。)(For testing purposes, http://myhostname:8172 generally works as well.)

publishUrl 端口设置为端口 8172,这是 Web 部署的默认端口。The publishUrl port is set to port 8172, which is the default for Web Deploy.

destinationAppUrl 端口设置为端口 80,这是 IIS 部署的默认端口。The destinationAppUrl port is set to port 80, which is the default for IIS.

如果使用主机名无法在 Visual Studio 中连接到远程主机(在后续步骤中),请测试 IP 地址以代替主机名。If you are unable to connect to the remote host in Visual Studio using the host name (in later steps), test the IP address in place of the host name.

备注

如果要发布到在 Azure VM 上运行的 IIS,则必须在网络安全组中打开 Web 部署和 IIS 端口。If you are publishing to IIS running on an Azure VM, you must open the Web Deploy and IIS ports in the Network Security group. 有关详细信息,请参阅安装和运行 IIS。For detailed information, see Install and run IIS.

将此文件复制到运行 Visual Studio 的计算机上。Copy this file to the computer where you are running Visual Studio.

在 Visual Studio 中导入发布设置并进行部署Import the publish settings in Visual Studio and deploy

如果计算机上的 Visual Studio 中打开有 ASP.NET 项目,则在该计算机的解决方案资源管理器中右键单击该项目,然后选择“发布”。On the computer where you have the ASP.NET project open in Visual Studio, right-click the project in Solution Explorer, and choose Publish.

如果先前配置了任何发布配置文件,则“发布”窗格会显示。If you have previously configured any publishing profiles, the Publish pane appears. 点击“新建配置文件”。Click Create new profile.

在“选取发布目标”对话框中,点击“导入配置文件” 。In the Pick a publish target dialog box, click Import Profile.

导航到上一节中创建的发布设置文件的位置。Navigate to the location of the publish settings file that you created in the previous section.

在“导入发布设置文件”对话框中,导航到在上一部分创建的配置文件并选择该文件,然后单击“打开” 。In the Import Publish Settings File dialog, navigate to and select the profile that you created in the previous section, and click Open.

Visual Studio 开始执行部署过程,并且输出窗口将显示进度和结果。Visual Studio begins the deployment process, and the Output window shows progress and results.

如果出现任何部署错误,请单击“设置”以编辑设置。If you get an any deployment errors, click Settings to edit settings. 修改设置,然后单击“验证”以测试新设置。Modify settings and click Validate to test new settings. 如果找不到主机名,请尝试“服务器”和“目标 URL”字段中的 IP 地址而不是主机名 。If the host name is not found, try the IP address instead of the host name in the Server and Destination URL fields.

应用成功部署后,它应自动启动。After the app deploys successfully, it should start automatically. 如果在 Visual Studio 中无法启动应用,请在 IIS 中启动应用以验证其是否正常运行。If the app does not start from Visual Studio, start the app in IIS to verify that it runs correctly. 对于 ASP.NET Core,还需要确保将 DefaultAppPool 的“应用程序池”字段设置为“无托管代码” 。For ASP.NET Core, you also need to make sure that the Application pool field for the DefaultAppPool is set to No Managed Code.

在“设置”对话框中,单击“下一步”启用调试,选择“调试”配置,然后在“文件发布”选项下选择“删除目标处的其他文件” 。In the Settings dialog box, enable debugging by clicking Next, choose a Debug configuration, and then choose Remove additional files at destination under the File Publish options.

重要

如果选择发布配置,则在发布时,需要在 web.config 文件中禁用调试。If you choose a Release configuration, you disable debugging in the web.config file when you publish.

单击“保存”,然后重新发布应用。Click Save and then republish the app.

(可选)通过发布到本地文件夹进行部署(Optional) Deploy by publishing to a local folder

如果要使用 PowerShell、RoboCopy 将应用复制到 IIS,或者要手动复制文件,则可以使用此选项来部署应用。You can use this option to deploy your app if you want to copy the app to IIS using PowerShell, RoboCopy, or you want to manually copy the files.

在 Windows Server 计算机上配置 ASP.NET Core 网站Configure the ASP.NET Core Web site on the Windows Server computer

打开 Windows 资源管理器并创建新文件夹 C:\Publish,稍后将在其中部署 ASP.NET Core 项目。Open Windows Explorer and create a new folder, C:\Publish, where you will later deploy the ASP.NET Core project.

如果尚未打开,请打开“Internet Information Services (IIS) 管理器”。If it's not already open, open the Internet Information Services (IIS) Manager. (在服务器管理器的左窗格中,选择“IIS”。(In the left pane of Server Manager, select IIS. 右键单击服务器并选择“Internet Information Services (IIS)管理器”。)Right-click the server and select Internet Information Services (IIS) Manager.)

在左窗格中的“连接”下,转到“站点”。Under Connections in the left pane, go to Sites.

选择“默认网站”,选择“基本设置”,然后将“物理路径”设置为“C:\Publish”。Select the Default Web Site, choose Basic Settings, and set the Physical path to C:\Publish.

右键单击“默认网站” 节点,然后选择“添加应用程序” 。Right-click the Default Web Site node and select Add Application.

将“别名”字段设置为“MyASPApp”,接受默认应用程序池 (DefaultAppPool),并将“物理路径”设置“C:\Publish”。Set the Alias field to MyASPApp, accept the default Application Pool (DefaultAppPool), and set the Physical path to C:\Publish.

在“连接”下,选择“应用程序池”。Under Connections, select Application Pools. 打开“DefaultAppPool”,然后将应用程序池字段设置为“无托管代码”。Open DefaultAppPool and set the Application pool field to No Managed Code.

右键单击 IIS 管理器中的新站点,选择“编辑权限”,并确保 IUSR、IIS_IUSRS 或配置为访问 Web 应用的用户是具有读取和执行权限的授权用户。Right-click the new site in the IIS Manager, choose Edit Permissions, and make sure that IUSR, IIS_IUSRS, or the user configured for access to the web app is an authorized user with Read & Execute rights.

如果没有看到其中任何一个用户具有访问权限,请执行相应步骤将 IUSR 添加为具有读取和执行权限的用户。If you don't see one of these users with access, go through steps to add IUSR as a user with Read & Execute rights.

通过从 Visual Studio 发布到本地文件夹来发布和部署应用Publish and Deploy the app by publishing to a local folder from Visual Studio

还可以使用文件系统或其他工具发布和部署应用。You can also publish and deploy the app using the file system or other tools.

在“解决方案资源管理器” 中,右键单击项目节点并选择“发布” (对于 Web Forms,选择“发布 Web 应用” )。In the Solution Explorer, right-click the project node and select Publish (for Web Forms, Publish Web App).

如果先前配置了任何发布配置文件,则“发布”窗格会显示 。If you have previously configured any publishing profiles, the Publish pane appears. 单击“新建配置文件” 。Click New profile.

在“发布” 对话框中,选择“文件夹” ,单击“浏览” ,然后创建一个新文件夹“C:\Publish” 。In the Publish dialog box, select Folder, click Browse, and create a new folder, C:\Publish.

对于 Web Forms 应用,请在“发布”对话框中选择“自定义” ,输入配置文件名称,然后选择“确定” 。For a Web Forms app, choose Custom in the Publish dialog box, enter a profile name, and choose OK.

单击下拉列表中的“创建配置文件” (默认值为“发布” )。Click Create profile in the drop-down list (Publish is the default value).

在“发布” 对话框中,单击“设置” 链接,然后选择“设置” 选项卡。In the Publish dialog box, click the Settings link, and then select the Settings tab.

将配置设置为“调试” ,选择“在发布前删除所有现有文件” ,然后单击“保存” 。Set the configuration to Debug, select Delete all existing files prior to publish, and then click Save.

备注

如果使用发布生成,则在发布时,需要在 web.config 文件中禁用调试。If you use a Release build, you disable debugging in the web.config file when you publish.

单击“发布” 。Click Publish.

应用程序将项目的“调试” 配置发布到本地文件夹。The application publishes a Debug configuration of the project to the local folder. “输出”窗口中将显示进度。Progress shows in the Output window.

将 ASP.NET 项目目录从 Visual Studio 计算机复制到 Windows Server 计算机上为 ASP.NET 应用配置的本地目录中(本例中为 C:\Publish )。Copy the ASP.NET project directory from the Visual Studio computer to the local directory configured for the ASP.NET app (in this example, C:\Publish) on the Windows Server computer. 在本教程中,我们假设你进行手动复制,不过,你也可以使用其他工具,例如 PowerShell、Xcopy 或 Robocopy。In this tutorial, we assume you are copying manually, but you can use other tools like PowerShell, Xcopy, or Robocopy.

注意

如果需要更改代码或重新生成,则必须重新发布并重复此步骤。If you need to make changes to the code or rebuild, you must republish and repeat this step. 复制到远程计算机的可执行文件必须与你的本地源和符号完全匹配。The executable you copied to the remote machine must exactly match your local source and symbols. 如果没有这样做,则在尝试调试进程时,你会在 Visual Studio 中收到 cannot find or open the PDB file 警告。If you do not do this you will receive a cannot find or open the PDB file warning in Visual Studio when you attempt to debug the process.

在 Windows Server 上,通过在浏览器中打开应用来验证是否可以正常运行应用。On the Windows Server, verify that you can run the app correctly by opening the app in your browser.

如果应用无法正常运行,则说明服务器和 Visual Studio 计算机上安装的 ASP.NET 版本可能不匹配,或者 IIS 或网站配置可能有问题。If the app doesn't run correctly, there may be a mismatch between the version of ASP.NET installed on your server and your Visual Studio machine, or you may have an issue with your IIS or Web site configuration. 请重新检查前面的步骤。Recheck earlier steps.

在 Windows Server 上下载并安装远程工具Download and Install the remote tools on Windows Server

下载与 Visual Studio 版本匹配的远程工具版本。Download the version of the remote tools that matches your version of Visual Studio.

在要调试的远程设备或服务器上(而不是 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

兼容所有 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

兼容所有 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

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

Visual Studio 2013 文档中的下载页面Download page in Visual Studio 2013 documentation

Visual Studio 2012Visual Studio 2012

Visual Studio 2012 文档中的下载页面Download page in Visual Studio 2012 documentation

VersionVersion

链接Link

说明Notes

Visual Studio 2017Visual Studio 2017

兼容所有 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. For the most recent version of the remote tools, open the Visual Studio 2019 doc.

Visual Studio 2015Visual Studio 2015

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

Visual Studio 2013 文档中的下载页面Download page in Visual Studio 2013 documentation

Visual Studio 2012Visual Studio 2012

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.

备注

若要在 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.

在 Windows Server 上设置远程调试器Set up the remote debugger on Windows Server

在远程计算机上,从“开始”菜单中查找并启动“远程调试器” 。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.

当第一次(或在配置它之前)启动远程调试器时,将显示“远程调试配置”对话框。The first time you start the remote debugger (or before you have configured it), the Remote Debugging Configuration dialog box appears.

如果未安装 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.

请至少选择一种要对其使用远程工具的网络类型。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.

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

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

远程调试器正在等待连接。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:

\msvsmon.exe

备注

如果需要为其他用户添加权限,请更改远程调试器的身份验证模式或端口号,请参阅配置远程调试器。If you need to add permissions for additional users, change the authentication mode, or port number for the remote debugger, see Configure the remote debugger.

有关将远程调试器作为服务运行的信息,请参阅将远程调试器作为服务运行。For information on running the remote debugger as a service, see Run the remote debugger as a service.

从 Visual Studio 计算机附加到 ASP.NET 应用程序Attach to the ASP.NET application from the Visual Studio computer

在 Visual Studio 计算机上,打开要调试的解决方案(如果按照本文中的所有步骤操作,则为 MyASPApp)。On the Visual Studio computer, open the solution that you are trying to debug (MyASPApp if you are following all the steps in this article).

在 Visual Studio 中,单击“调试”>“附加到进程”(Ctrl + Alt + P)。In Visual Studio, click Debug > Attach to Process (Ctrl + Alt + P).

提示

在 Visual Studio 2017 及更高版本中,可以使用“调试”>“重新附加到进程...”重新附加到以前附加到的同一进程(Shift + Alt + P)。In Visual Studio 2017 and later versions, you can reattach to the same process you previously attached to by using Debug > Reattach to Process... (Shift + Alt + P).

将限定符字段设置为 ,并按 Enter 。Set the Qualifier field to and press Enter.

确保 Visual Studio 将所需的端口添加到计算机名称中,其格式为::portVerify that Visual Studio adds the required port to the computer name, which appears in the format: :port

在 Visual Studio 2019 中应看到 :4024On Visual Studio 2019, you should see :4024

在 Visual Studio 2017 中应看到 :4022On Visual Studio 2017, you should see :4022

端口是必需的。The port is required. 如果看不到端口号,请手动添加。If you don't see the port number, add it manually.

单击“刷新”。Click Refresh.

“可用进程” 窗口中将显示某些进程。You should see some processes appear in the Available Processes window.

如果看不到任何进程,请尝试使用 IP 地址而不是远程计算机名称(端口是必需的)。If you don't see any processes, try using the IP address instead of the remote computer name (the port is required). 可以在命令行中使用 ipconfig 来获取 IPv4 地址。You can use ipconfig in a command line to get the IPv4 address.

如果要使用“查找”按钮,则可能需要在服务器上打开 UDP 端口 3702。If you want to use the Find button, you may need to open UDP port 3702 on the server.

勾选“显示所有用户的进程” 。Check Show processes from all users.

键入进程名称的第一个字母,以快速查找应用。Type the first letter of your process name to quickly find your app.

如果正在 IIS 上使用进程内托管模型,请选择正确的 w3wp.exe 进程。If you're using the in-process hosting model on IIS, select the correct w3wp.exe process. 从 .NET Core 3 开始,这是默认设置。Starting in .NET Core 3, this is the default.

否则,请选择 dotnet.exe 进程。Otherwise, select the dotnet.exe process. (这是进程外托管模型。)(This is the out-of-process hosting model.)

如果有多个进程显示 w3wp.exe 或 dotnet.exe,请检查“用户名”列。If you have multiple processes showing w3wp.exe or dotnet.exe, check the User Name column. 在某些情况下,“用户名”列显示应用池名称,例如 IIS APPPOOL\DefaultAppPool。In some scenarios, the User Name column shows your app pool name, such as IIS APPPOOL\DefaultAppPool. 如果你看到了应用池,但它不是唯一的,则为要调试的应用实例创建一个使用新名称的应用池,然后就可以在“用户名”列中轻松找到它了。If you see the App Pool, but it's not unique, create a new named App Pool for the app instance you want to debug, and then you can find it easily in the User Name column.

单击 “附加” 。Click Attach.

打开远程计算机的网站。Open the remote computer's website. 在浏览器中,转到 http://。In a browser, go to http://.

将显示 ASP.NET 网页。You should see the ASP.NET web page.

在正在运行的 ASP.NET 应用程序中,单击指向“关于”页面的链接。In the running ASP.NET application, click the link to the About page.

应在 Visual Studio 中命中断点。The breakpoint should be hit in Visual Studio.

排除故障:在 Windows Server 上打开必需端口Troubleshooting: Open required ports on Windows Server

在大多数设置中,必需端口通过安装 ASP.NET 和远程调试器来打开。In most setups, required ports are opened by the installation of ASP.NET and the remote debugger. 但是,你可能需要验证端口是否已打开。However, you may need to verify that ports are open.

备注

在 Azure VM 上,必须通过网络安全组打开端口。On an Azure VM, you must open ports through the Network security group.

必需端口:Required ports:

80 - 对于 IIS 是必需的80 - Required for IIS

4024 - 从 Visual Studio 2019 进行远程调试时必需(有关详细信息,请参阅远程调试器端口分配)。4024 - Required for remote debugging from Visual Studio 2019 (see Remote Debugger Port Assignments for more information).

4022 - 从 Visual Studio 2017 进行远程调试时必需(有关详细信息,请参阅远程调试器端口分配)。4022 - Required for remote debugging from Visual Studio 2017 (see Remote Debugger Port Assignments for more information).

UDP 3702 -(可选)发现端口允许你在附加到 Visual Studio 中的远程调试器时使用“查找”按钮。UDP 3702 - (Optional) Discovery port enables you to the Find button when attaching to the remote debugger in Visual Studio.

若要在 Windows Server 上打开端口,请打开“开始”菜单,搜索“高级安全 Windows 防火墙”。To open a port on Windows Server, open the Start menu, search for Windows Firewall with Advanced Security.

然后选择“入站规则”>“新建规则”>“端口”,单击“下一步”。Then choose Inbound Rules > New Rule > Port, and then click Next. (对于 UDP 3702,请改为选择“出站规则”。)(For UDP 3702, choose Outbound Rules instead.)

在“特定本地端口”下,输入端口号,然后单击“下一步”。Under Specific local ports, enter the port number, click Next.

单击“允许连接”,单击“下一步”。Click Allow the Connection, click Next.

选择要为端口启用的一个或多个网络类型,然后单击“下一步”。Select one or more network types to enable for the port and click Next.

你选择的类型必须包括远程计算机连接到的网络。The type you select must include the network to which the remote computer is connected.

为入站规则添加名称(例如,IIS、Web 部署或 msvsmon),然后单击“完成”。Add the name (for example, IIS, Web Deploy, or msvsmon) for the Inbound Rule and click Finish.

应该能在“入站规则”或“出站规则”列表中看到自己的新规则。You should see your new rule in the Inbound Rules or Outbound Rules list.

如果需要有关配置 Windows 防火墙的详细信息,请参阅配置 Windows 防火墙以便进行远程调试。If you want more details on configuring Windows Firewall, see Configure the Windows Firewall for Remote Debugging.

为其他必需端口创建附加规则。Create additional rules for the other required ports.

core部署iis的 调试net_远程调试远程 IIS 计算机上的 ASP.NET Core - Visual Studio | Microsoft Docs...相关推荐

  1. vs2017附加linux进程,使用调试器附加到运行的进程 - Visual Studio | Microsoft Docs

    使用 Visual Studio 调试器附加到正在运行的进程Attach to running processes with the Visual Studio debugger 06/12/2020 ...

  2. c# uwp html源码,调试 UWP 应用中的 HTML 和 CSS - Visual Studio | Microsoft Docs

    在 Visual Studio 中调试 UWP 应用中的 HTML 和 CSS 07/17/2018 本文内容 Visual Studio 针对 JavaScript 应用提供全面的调试体验,其中包括 ...

  3. clickonce 部署能cs程序_配置 ClickOnce 信任提示行为 - Visual Studio | Microsoft Docs

    如何:配置 ClickOnce 信任提示行为How to: Configure the ClickOnce trust prompt behavior 11/04/2016 本文内容 您可以配置 Cl ...

  4. 远程桌面服务器office版本,在启用远程桌面服务的计算机上部署 Office 2010

    适用于: Office 2010 上一次修改主题: 2016-11-29 可以按照本文中的以下步骤在启用远程桌面服务的计算机上安装 Office 2010.远程桌面服务(之前称为终端服务)是 Wind ...

  5. ASP.NET Core 实战:将 .NET Core 2.0 项目升级到 .NET Core 2.1

    一.前言  最近一两个星期,加班,然后回去后弄自己的博客,把自己的电脑从 Windows 10 改到 Ubuntu 18.10 又弄回 Windows 10,原本计划的学习 Vue 中生命周期的相关知 ...

  6. VS 远程调试 Azure Web App

    如果能够远程调试部署在 Azure 上的 Web App,将会极大的提高我们修复 bug 的效率.Visual Studio 一贯以功能强大.好用著称,当然可以通吃基于 Azure 应用的创建.发布和 ...

  7. linux java远程调试_Visual Studio 2017 Linux远程调试(gdbserver)

    在我的远程计算机(Ubuntu 16.04.4 LTS)上安装gdbserver之后,我通过在Visual Studio 2017中创建"跨平台控制台应用程序(linux)"项目来 ...

  8. VS.net中的远程调试

    简介: 我们开发完一个软件后,提交给客户或者放到服务器上执行,如果有问题,我们可以使用远程调试进行发现bug. 这篇文字简单介绍一下远程调试. vs.net远程调试服务 在vs.net的安装目录下,有 ...

  9. Asp.Net Core 开发热更新/重载(Hot Reload)及调试 VSC 配置

    对于开发过程的效率帮助: asp.net core原生应用热更新,包括Razor界面.C#代码文件等的修改后触发重载. 在使用热更新模式后,同时可以进行调试. 热更新(重载)命令为: dotnet w ...

最新文章

  1. 5分钟!用Java实现目标检测 | PyTorch
  2. 其实win10要比win7的安全性强很多
  3. python实现交并比IOU
  4. ​通俗理解神经网络BP反向传播算法
  5. 一文讲清数据治理、数据管理、数据资产管理区别,数据专家必看
  6. 一个用户在同一时间只能登录一次
  7. python人名抽签_办公人员的 python 妙用——抽签结果提取
  8. Hyperledger Fabric CA中文文档
  9. python爬虫 - 爬取堆糖图片
  10. Maya---物体跟随曲线动画
  11. h5自动播放视频且有声音的办法
  12. 无极电影的php,php无极
  13. adroid xpose 修改java方法实例_基于xposed 修改硬件信息(xposed框架使用)
  14. 嵌入式系统——复杂指令集系统与精简指令集系统(CISCRISC)
  15. Credit Card Fraud Detection(信用卡诈欺侦测)Spark建模
  16. 深入理解双亲委托机制
  17. C语言初学基础篇:编译型语言和解释型语言
  18. logstash简介及基本操作
  19. 关于HTTP中的数据协商
  20. scrapy 使用浏览器的开发人员工具进行抓取

热门文章

  1. 概率统计笔记:高斯威沙特分布
  2. 数学在机器学习中的作用
  3. Python入门100题 | 第052题
  4. Online Learning场景下实时新闻热点机器学习训练实践
  5. android源码出现的@字符意义总结
  6. 第五章--预处理理论
  7. Lesson 4.5 梯度下降优化基础:数据归一化与学习率调度
  8. ADSL宽带为什么下载和上传速度差别如此之大?
  9. 布道微服务_07服务调用追踪
  10. Apache Kafka-生产消费基础篇