Press F5 on a plug-in project and Visual Studio tells you a class library can’t be started directly. It’s right. A plug-in isn’t a program. It’s a DLL that runs inside TeklaStructures.exe, so you don’t start it. You join it.
This is how I debug mine: attach to the running Tekla, and let Debugger.Launch() call Visual Studio for the code I can’t catch by hand. Here’s the whole loop, with the places it breaks.
Tekla locks your DLL, so a post-build copy fails
Tekla loads plug-ins from its extensions folder when it starts and keeps the files open for the whole session. The first idea everyone has, a post-build step that copies the DLL into extensions, fails with “file in use” and takes the build down with it. Deploy as a separate step, with Tekla closed, and copy the .pdb along with the DLL. Without it, Visual Studio has nothing to map your breakpoints to.
@echo off
REM deploy.bat: run with Tekla CLOSED, it locks the DLL while it's open
set "SRC=%~dp0bin\Debug\net48"
set "DEST=C:\ProgramData\Trimble\Tekla Structures\2024.0\Environments\common\extensions\MyPlugin"
if not exist "%DEST%" mkdir "%DEST%"
copy /Y "%SRC%\MyPlugin.dll" "%DEST%" || (echo COPY FAILED - is Tekla still open? & exit /b 1)
copy /Y "%SRC%\MyPlugin.pdb" "%DEST%" || (echo COPY FAILED - is Tekla still open? & exit /b 1)
Not sure which folder your Tekla scans? The XS_EXTENSION_DIRECTORY advanced option lists them. Tekla only looks at that folder when it starts, so every new build means a restart.
Attach first, then run the plug-in
- Start Tekla and open a model.
- In Visual Studio: Debug → Attach to Process (Ctrl+Alt+P), pick
TeklaStructures.exe, Attach. - Put breakpoints in
DefineInput()andRun(). - Now start the plug-in from Applications & components and pick the input.
There’s no race here. DefineInput() and Run() only fire when someone triggers the plug-in, so you always have time to attach. After the next restart, Debug → Reattach to Process (Shift+Alt+P) saves you the process list.
Hollow breakpoints mean Tekla loaded a different DLL
You’re attached, the plug-in runs, and the breakpoints stay hollow circles. Almost always, the DLL Tekla loaded isn’t the one you just built. You rebuilt but didn’t redeploy, or you redeployed but didn’t restart Tekla, or the .pdb in the extensions folder is from an older build. If Visual Studio’s Attach to: Automatic picked native code only, set it to Managed (.NET Framework 4.x).
To stop guessing which build is loaded, have the plug-in say so. Write the DLL’s build time to Tekla’s status bar:
using System.IO;
using Tekla.Structures.Model.Operations;
var dll = typeof(MyPlugin).Assembly.Location;
Operation.DisplayPrompt($"MyPlugin built {File.GetLastWriteTime(dll):HH:mm:ss}"); // stale time = stale DLL
If the time is from this morning and you built five minutes ago, no debugger setting will help.
Debugger.Launch(): let the plug-in call Visual Studio
Some code runs before you can attach. And after the tenth restart of the day, attaching by hand gets old. Debugger.Launch() turns it around: the plug-in asks Windows for a debugger, a dialog lists your open Visual Studio instances, you pick the one with your solution, and it stops on that line.
public override bool Run(List<InputDefinition> input)
{
#if DEBUG
if (!Debugger.IsAttached) Debugger.Launch(); // never ships: Release builds skip this line
#endif
try
{
return new BeamWorker(_data).Run(input); // the real work lives in a worker class
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString()); // full stack trace, not just Message
return false;
}
}
Keep the #if DEBUG. A stray Launch() in a shipped DLL pops that dialog on a detailer’s machine in the middle of their work. Also, the dialog only lists full Visual Studio. VS Code can’t register as that kind of debugger, so with VS Code you attach by hand.
The bug the debugger won’t stop on
A debugger is good at exceptions. Tekla mostly doesn’t throw them. Insert() and Modify() return false when they reject a bad profile string or collinear points, and the run carries on. The plug-in “works” and nothing appears in the model.
bool inserted = beam.Insert(); // false = rejected, no exception: break here, read beam.Profile.ProfileString
if (!inserted)
throw new InvalidOperationException($"Insert failed for profile '{beam.Profile.ProfileString}'");
Turn every false into something you can see, and the debugger has something to stop on. And if the plug-in never shows up in Applications & components at all, open File → Logs → Session history log before you open Visual Studio. Load failures are written there.
The loop, short version
- Build, close Tekla, deploy DLL +
.pdb, start Tekla. - Attach to
TeklaStructures.exebefore you trigger the plug-in. - Hollow breakpoints: check the build time Tekla shows you before you touch any setting.
Debugger.Launch()inside#if DEBUG, never outside it.- Check what
Insert()returned. Silence isn’t success.
Restart less, debug less. Every change to a plug-in costs a Tekla restart. That’s why the Tekla Open API skill keeps the plug-in class thin and puts the real work in worker classes: most of the logic can then be tested from an exe that connects to a running Tekla, with plain F5. In the course you build plug-ins that way from the first one, and there’s a whole lesson on debugging, breakpoints included.
Tekla Open API Course: build real Tekla tools with an AI agent →
Related: Tekla Open API 2024 upgrade: why your exe stops connecting · Tekla UDAs from C#: why GetUserProperty returns false · GetReportProperty: types, units and the silent false
