0

I'm writing some code that integrates with Umbraco v7, at the moment specifically with the Umbraco Forms extension but in the near future with the CMS itself. I have nuget'd the Umbraco assemblies into my VS project and have a working instance with all the relevant packages and customisations in place by following the steps described in this article.

I have a second project, let's call it Project2 in the solution which will generate the DLL I'll be dropping into Umbraco's bin folder in production to allow the CMS to auto-hook-up to the additional functionality.

So far all well and good, but I have hit a problem - debugging. If I drop the Project2 dll into Umbraco I can use the Umbraco logger to generate output messages but this is woefully inadequate for debugging more complex code, not to say frustratingly time-consuming. But I can't see how I can connect the Visual Studio debugger to Project2 at runtime. Can anyone suggest a technique I could utilise?

immutabl
  • 6,857
  • 13
  • 45
  • 76
  • are you running this locally? Have you tried to attach your debugger? – Mario Jun 09 '16 at 22:38
  • I'm running the Umbraco instance in IIS Express and manually dropping the Project2 dll into the bin folder after building. This doesn't play with the debugger. – immutabl Jun 09 '16 at 23:40

1 Answers1

0

I've sort of figured it out with the aid of this post which at least allows me to hook into things like events like Published with my own code which can be debugged in VS.

The technique is this:

  1. Edit the Global.ascx file in the main Umbraco project so that it uses a custom Global.cs file in Project2. Of course you have to add a reference to Project2 in the main Umbraco project in order to do this. This is your hook.

    <%@ Application Inherits="Project2.Global" Language="C#" %>
    
  2. And in this file (which is in Project2) you attach custom handlers for the various Umbraco events. And from this point in all the hooks are in place to allow you to debug your custom code. Slap some breakpoints in there and kiss the LogHelper goodbye ;-)

       public class Global : UmbracoApplication
       {
           public override void Init()
           {
               var application = this as HttpApplication;
               //Hook up your event handlers as required.
               application.PreRequestHandlerExecute += PreRequestHandlerExecute;
           ContentService.Published += ContentService_Published;
               base.Init();
           }
           //Custom logic which you can step-through in VS.
           private void ContentService_Published(IPublishingStrategy sender,
        PublishEventArgs<Umbraco.Core.Models.IContent> e)
           {
               LogHelper.Info(this.GetType(), "Caught Publish event " + e.PublishedEntities.FirstOrDefault().Name);  //very droll.
           } 
            ...
        }
    

Phew! Hope this helps someone.

Community
  • 1
  • 1
immutabl
  • 6,857
  • 13
  • 45
  • 76