core部署iis的 调试net_远程调试远程 IIS 计算机上的 ASP.NET Core - Visual Studio | Microsoft Docs...
在 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...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: charset参数 sqluldr2_s
- 下一篇: 华为p4支持鸿蒙功能吗_华为鸿蒙系统可以