Documentation Center

Debugging a .NET assembly Template Building Block

This procedure describes a scenario in which the Content Manager server and Visual Studio are on the same machine. If they are on separate machines, you must debug remotely.

Procedure

  1. Ensure that a new .NET assembly can be uploaded to the Content Manager as a Template Building Block. Refer to Creating a .NET assembly Template Building Block to learn how. Be sure to configure the upload tool to include .pdb files when uploading the assembly; these files are used for debugging.
  2. Start Visual Studio and open the .NET assembly project.
  3. Start Template Builder and open or create a Template.
  4. Set a breakpoint somewhere in your code.
  5. From the main menu, select Debug > Attach to Process.
    The Attach to Process dialog opens.
  6. In this dialog, the Available Processes table displays processes running on this machine. Locate the running process called TcmTemplateDebugHost and select it. Then click Attach.
  7. The debugger now attaches itself to the process.
    Note the following:
    • If, during debugging, you experience problems working with TcmTemplateDebugHost, try closing it down. It automatically restarts when needed.
    • To be able to detach from a process when you finish debugging (you are otherwise forced to quit the process after debugging), in the Attach to process dialog, go to the Attach to subdialog, select Debug these code types and select the Managed Code option.

Results

  • You can now set breakpoints in your code in Visual Studio, run a Template that contains a Template Building Block referring to your .NET assembly, and processing of that Templating Building Block halts when it reaches your breakpoint.
  • You can then step through your .NET code, examine variables and perform all normal Visual Studio debugging functions. When you resume processing, Template Builder continues with the next Template Building Block (if the run was successful).