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
- 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.
- Start Visual Studio and open the .NET assembly project.
- Start Template Builder and open or create a Template.
- Set a breakpoint somewhere in your code.
- From the main menu, select .
The Attach to Process dialog opens.
- 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.
Note:
If multiple users are debugging an assembly at the same time, you will see multiple entries in the table for TcmTemplateDebugHost. In that case, identify your specific instance of this process by checking the ID. You can find out the ID of your process by checking the Output view in Template Builder, which contains the following line:
Debugging was started in process 'TcmTemplateDebugHost' with id
7728
where 7728 is the ID of the process.
Note: You can also debug a .NET Template Building Block from the Content Manager Explorer interface while you preview or publish a Component or Page. To do so, attach to a different process:
- To debug while previewing, attach to TcmServiceHost.exe
- To debug while publishing, attach to TcmPublisher.exe
- 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).