Cultiv Web Solutions

Easily debug your custom Umbraco user controls in Visual Studio

Easily debug your custom Umbraco user controls in Visual Studio Easily debug your custom Umbraco user controls in Visual Studio I've been looking for the best way to debug when creating user controls for Umbraco, and there were no complete instructions available online. The simplest way for me has been as follows. When I create a new Umbraco website, I ) Easily debug your custom Umbraco user controls in Visual Studio

I've been looking for the best way to debug when creating user controls for Umbraco, and there were no complete instructions available online.

The simplest way for me has been as follows.

When I create a new Umbraco website, I make a structure in my development folder of three folders under the site's name:

Database
UmbracoFramework
UmbracoModules

Logically, my database mdf/ldf files go into the "Database" folder. I do this to have everything belonging to the site close together.

In UmbracoFramework, I place the cleanly downloaded files of Umbraco's install. I've changed the default web.config to the .Net 3.5 version, using directory URL's.

One important thing to note is that, for this to work in Windows 7 (and probably Vista), you need to run Visual Studio as Administrator. If you don't, the debug session won't start. If there's any work-arounds for this, I'd love to know.

So let's see what we'd need to do in Visual Studio.

After starting VS2008, we create a new (blank) solution for this project.

umbvs08_01

Then we add an existing website (note you can do this either before installing Umbraco locally or right after right, it doesn't matter).

umbvs08_02

In your build configuration manager, make sure never to build this project, there's no need.

umbvs08_03

Now we can start creating a user control, add a new ASP.NET Web Application project in the folder UmbracoModules. We'll call this one (surprise!) "HelloWorld".

So a HelloWorld folder will be created under UmbracoModules.

umbvs08_05

We won't need the web.config and default.aspx, so I delete them.

We can automatically copy the dll/pdb files and the ascx files to the UmbracoFramework folder during each build. This is done using the post-build events:

XCOPY "$(ProjectDir)bin\HelloWorld.*" "$(ProjectDir)..\..\UmbracoFramework\bin\" /y
XCOPY "$(ProjectDir)*.ascx" "$(ProjectDir)..\..\UmbracoFramework\usercontrols\" /y

Note that "Helloworld.*" is the name of the dll/pdb's we want to copy. Don't use *.* here if you reference the Umbraco framework files, else they'll get copied over the existing verions each time.

umbvs08_06

For both the UmbracoFramework AND the new module, we'll change the default webserver into a "custom" one. This is just a link to the local domain name we created in IIS.

umbvs08_07

umbvs08_07_1

Once everything is saved, we're done. We can start creating a new user control and put breakpoints in them.

umbvs08_08

Hit F5 and see what happens.

umbvs08_09

Voila! A breakpoint being hit, we can start debugging.

 

3 comments on this article

Avatar for Jay Greasley Comment from Jay Greasley
Very useful, thanks.

Avatar for Donald Burgess Comment from Donald Burgess
Hello Jay
I have followed your instruction and also created a entry in IIS7 to create a website "UmbracoDevelop" with a physical path to "C:\users\admin\documents\projet1\UmbracoDevelop"
the folders UmbrcoFramework and UmbracoModules are in the UmbracoDevelop folder. I have set the custom Web Server to http://UmbracoDevelop for both HelloWord and UmbracoFramework.
Also checked all the permission and they seem OK.

However, when I run debug (F%5) I get an error "Unable to start debugging on the web server. The debugger cannot connect to the remote computer. ..."

Is there something I am missing in the instruction?

Thanks
Don

Avatar for Brendan Rice Comment from Brendan Rice
I keep referring to your article for the post build events, think I owe you a "thank you" :)

Add your comment