Proof of concept PowerShell Script for Building TwinCAT Solutions via C# DTE to dte.ToolWindows.ErrorList.ErrorItems
This guide is a personal project and not a peer-reviewed publication or sponsored document. It is provided “as is,” without any warranties—express or implied—including, but not limited to, accuracy, completeness, reliability, or suitability for any purpose. The author(s) shall not be held liable for any errors, omissions, delays, or damages arising from the use or display of this information.
All opinions expressed are solely those of the author(s) and do not necessarily represent those of any organization, employer, or other entity. Any assumptions or conclusions presented are subject to revision or rethinking at any time.
Use of this information, code, or scripts provided is at your own risk. Readers are encouraged to independently verify facts. This content does not constitute professional advice, and no client or advisory relationship is formed through its use.
This repository provides a PowerShell script that bypasses the limitation of accessing dte.ToolWindows.ErrorList.ErrorItems. Instead of attempting a direct cast from DTE to DTE2, it uses embedded C# to create the DTE instance and retrieve build errors. Normal DTE operations remain fully supported.
- Windows PowerShell 5.1 or PowerShell 7+ (must run with
-STA). - TwinCAT XAE Shell installed, with:
EnvDTE.dllEnvDTE80.dll
Typically found under:
C:\Program Files (x86)\Beckhoff\TcXaeShell\Common7\IDE\PublicAssemblies\
- TwinCAT 3 Solution file (
.sln) to build.
Adjust the following variables in the script:
$SolutionPath = "$env:UserProfile\Desktop\ps-dte-errorlist\example\example.sln"
$ProgId = "TcXaeShell.DTE.15.0"
$MakeVisible = $true
$envDte = "C:\Program Files (x86)\Beckhoff\TcXaeShell\Common7\IDE\PublicAssemblies\EnvDTE.dll"
$envDte80 = "C:\Program Files (x86)\Beckhoff\TcXaeShell\Common7\IDE\PublicAssemblies\EnvDTE80.dll"$SolutionPath: Absolute path to your.slnfile.$ProgId: ProgID for the TwinCAT XAE shell. Adjust version as needed.$MakeVisible: Set to$trueto make the Visual Studio window visible during build.$envDte/$envDte80: Paths to EnvDTE assemblies.
Clone or copy the script into your local environment. No package installation is required.
Run the script in an STA PowerShell session:
pwsh -STA -File .\Build-TwinCAT.ps1The script will:
- Launch a new TwinCAT XAE instance (
DTE). - Open the configured
.slnsolution file. - Trigger a build.
- Wait for build completion.
- Output build status:
- Success → "Build succeeded."
- Failure → Prints error list entries with file, line, column, and description.