How to use VS2012 remote debug Windows Azure Cloud Services

Background:

Windows Azure Cloud Services 可以在本地調試,使用Visual Studio 2012 + 模擬器 Emulator。但是模擬器的工作狀態和環境和真實的雲環境還是有區別的。

所以有些問題,需要遠程調試(Remote Debug)

Steps:

1、Local :Install IDE Visual Studio 2012 at local

2、Remote Machine:遠程機器需要安裝Remote Tools for Visual Studio 2012 Update 2

  下載地址:rtools_setup_x64.exe 選擇正確的操作系統版本(32位的工具只能Debug 32位的程序,64位的調試64位程)。

Note:一般遠程調試,準備上述就可以了。Cloud Service的Instance安裝Remote Tools可以放在Setup WebRole 或者WorkRole 的時候同時安裝Debug工具。

3. Upload rtools_setup_x64.exe to storage blob container named "Tools".

4. Cloud Service

1)Create Cloud Service with a webrole instance(asp.net mvc4 with empty template).

2) Write code to install Remote Tools in Role OnStart method. Will be attached the detail code about how to implement method StartStopDebugService().

   public override bool OnStart()

        {

            // For information on handling configuration changes

            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

 

            RoleEnvironment.Changing += RoleEnvironmentChanging;

            RoleEnvironment.Changed += RoleEnvironmentChanged;

 

            try

            {

                StartStopDebugService();

            }

            catch (Exception ex)

            {

                //Trace Startup Exception

                Trace.TraceError(ex.Message);

 

                throw;

            }

 

            return base.OnStart();

        }

 3)Configuration

Double click webrole under cloud service porject to edit properties.

Settings:

 Endpoint:

The endpoint RemoteDebugger with public port 4016 is used for local Visual Studio connecting to the remote debugger process.

Local Storage:

When web role starting, it will download remote tool from storage blob contrainer to local storage, and then install it. 

   

5. Publish cloud service

Configurate publish settings with default.

6. Debug

1) Open website of the cloud service

2) Set breakpoints in VS

3) Open Debug->Attach to process

if w3wp.exe process doesn't in the available prcesses list, please refesh website.

   

7. Source Code

WindowsAzureRemoteDebug.zip

I have removed reference packages from the solution, if you want build successfully, you should add them yourself.

7. Enjoy debuging.

If you have any question, feel free to ask me by repling comment.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章