Remotely debug Azure Web App

When we deploy Web App on Azure, if we can realize remote debugging, it will greatly improve the efficiency of our bug fixing. Visual Studio has always been known for being powerful and easy to use, and of course it can create, publish, and debug Azure-based applications. Next, let's take a look at how to use Visual Studio to remotely debug a Web App deployed on Azure, and some common considerations.

Article source: Grape City Product Technology Community

Note the version of the tool

Before starting the main text let's check the Azure SDK version and Visual Studio version used. According to the introduction of MSDN, the remote debugging function of Azure is added in Azure SDK 2.2, so please make sure that 2.2 or an updated Azure SDK is installed on your machine.

There is also an interesting description on MSDN about the Visual Studio version issue. The general idea is that using Visual Studio 2012 can already debug a website on Azure remotely, but Visual Studio 2013 has made a lot of improvements. Personal understanding is best to use VS2013, or a newer version.

The experimental environment of the author at the time of writing this article is VS2015 update3 and Azure SDK 2.9.

 

Introduction

If we want to use Visual Studio running on machine A to debug a program myapp running on another machine B (visual studio is not installed on machine B), we should not only deploy the myapp program with the pdb file to machine B, but Also run a debugging aid, msvsmon.exe, on machine B. After running msvsmon.exe, Visual Studio will be able to attach myapp and use its pdb file for debugging, which is Visual Studio's remote debugging feature. The msvsmon.exe program must match a specific version of Visual Studio to work, so it is integrated in the Visual Studio installation package, and you can find it by searching in the Visual Studio installation directory.

Remote debugging of Azure Web App is the same as the above process, except that we need to specify the Visual Studio version corresponding to msvsmon.exe through the cloud configuration, and tell the cloud to open some ports required for debugging.

Let's take a step-by-step VS remote debugging Azure App journey.

 

Set Deployment credentials

When we deploy the website, we need to create this account, which can be used for both deployment and remote debugging.

 

 

Download the publishing profile for publishing

Publishing profile is the profile used for publishing operations. When we want to publish a website or a web application, we need a lot of basic information, such as where is the server? What is the username? What's the password? Wait... These information are all saved in the publishing profile file, and interested friends can open this file to see the detailed information inside.

Whether debugging or not, we have to publish the application to Azure, so download the publishing profile first:

 

 

Allow remote debugging of Web App

设置 Application settings 中的远程调试为允许状态,并指定用于远程调试的 Visual Studio 版本。相关内容已经在原理部分讲过,这里说些需要注意的内容:

这两项设置是有期限的,在48小时之后默认会被关掉!

原因主要是性能和安全,所以建议大家在调试完成后立即关闭远程调试功能。

 

 

发布调试版本的 Web App

Visual Studio 的调试功能依赖于编译过程中产生的 pdb 文件。下面的设置就是让 Web App 在发布时编译为 debug 版本并产生对应的 pdb 文件。现在的 Visual Studio 已经可以智能的去找 pdb 文件了,所以这里我们不用关心 pdb 文件是被发布到了云端还是保存在本地(简单就好)!

先导入刚才下载的 publishing profile 文件:

 

在 Settings 中选择 Configuration 为 ”Debug”:

 

然后点击 “Publish”按钮进行发布。

 

Attach 远程进程

在 Attach 对话框中输入网站 URL 中去掉”http://”的部分,然后在弹出的对话框中输入我们在最开始处创建的用户名和密码。

 

在列出的进程列表中选择”w3wp.exe”:

 

点击”Attach”按钮就可以了。

心急的同学可要注意了,这里可能需要等待上那么一小会儿…

 

开始远程调试 Web App

当你看到设置的断点变成可用状态时,就可以尝试去触发一个断点了。

 

好了,看上去还不赖,能够工作了!

注意,实际使用过程中可能并不会这么的顺利。主要是在 attach 的时候,可能需要多试几次才能成功。调试的过程中速度也是个问题,感觉还是有点慢。

另外,调试 Web 程序经常会碰到让人很尴尬的一幕:正好有另外的一个用户在使用这个功能(可能是测试人员),此时不要太吃惊喔!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326273060&siteId=291194637