Samples | Visual Studio // Read error list ErrorList errorList = dte2.ToolWindows.ErrorList; ErrorItems errors = errorList.ErrorItems; for (int i = 1; i { ErrorItem item = errors.Item(i); Console.WriteLine($"[{item.ErrorLevel}] {item.Description} ({item.FileName}:{item.Line})"); } The error list window displays status messages for various functions of the Visual Studio development environment and, consequently, the TwinCAT development environment as well. Every ErrorItem object has the following properties: DTE2 (from EnvDTE80 ) is the more modern version compared to DTE . The build output pane is called exactly "Build" . The index in errors.Item(i) is 1-based.
The last four properties are not always populated – an error message such as “No license found” is not tied to a specific file or line. Reading the error list in PowerShell Since PowerShell accesses COM objects via late binding, the direct cast from DTE to DTE2 used in C# cannot be applied here. This results in the loss of type information, which prevents reliable casting. The recommended solution compiles the C# logic at runtime using Add-Type directly in PowerShell and executes it. This means that early binding will continue to be used with the Interop assemblies. Requirements PowerShell 5.x or 7.x and TwinCAT XAE must be installed.
Problem and solution The C# approach in PowerShell fails because PowerShell does not correctly resolve the ErrorItems collection during DTE2 late binding: # FUNKTIONIERT NICHT (Late Binding Fehler): # $errors = $dte2.ToolWindows.ErrorList.ErrorItems PowerShell 5 solution:
# Locate the Visual Studio installation path using vswhere.exe, # which ships with every VS installation since 2017 # only useable when VisualStudio is installed $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $installPath = & $vswhere -latest -property installationPath # For TcXaeShell version 4026+ $installPath = 'C:\Program Files\Beckhoff\TcXaeShell' # Locate the Microsoft.VisualStudio.Interop assembly dynamically, # since its exact path varies depending on the VS version and edition $interopDll = Get-ChildItem "$installPath" -Recurse -Filter "Microsoft.VisualStudio.Interop.dll" | Select-Object -First 1 # Load assemblies via Reflection instead of Add-Type -Path, # because LoadFrom is more tolerant of missing transitive dependencies $asmEnvDTE = [System.Reflection.Assembly]::LoadFrom("$installPath\Common7\IDE\PublicAssemblies\Env DTE.dll") $asmEnvDTE80 = [System.Reflection.Assembly]::LoadFrom("$installPath\Common7\IDE\PublicAssemblies\Env DTE80.dll") TE1000 190 Version:
1.7.0 Property Description Description Describes the error message. FileName The name of the file in which the error occurred. Line The line in which the error occurred. Column The column in which the error occurred. Project Project in which the error occurred.