The TIA Add-In Build Package creates and manages all necessary files to develop and debug a TIA Add-In. After installing the build package, the project is ready for development and no further setup is required.
This project serves as documentation and issue tracker only.
- Automatic referencing of the
Siemens.Engineering.AddIn
assembly from the TIA Portal installation - Template files
- view provider and shortcut menu template files are created
- improved support for unhandled exceptions
- Creating and dynamically updating of the Add-In publisher configuration
- configuration is fully preconfigured
- automatic detection of dependencies (AdditionalAssemblies)
- automatic detection of certificates in the project structure
- Post build event for converting (*.dll -> *.addin) of the TIA Add-In
- *.addin is automatically deployed into the TIA Portal installation (requires admin privileges)
- Improved error handling for unhandled exceptions
- Errors are displayed as a message box before the add-in is terminated
- Extension methods for
- recursive finding of all devices in the project
- get all PLCs, Drives, ...
- iterate through all parents
- and more ...
- Deployment of TIA Add-In Tester
- Debug configuration is preset
- Add-In is immediately ready for testing/debugging without copying and installing it in the TIA Portal
Create a new class library project or install the package into an existing project.
- right click the add-in project and select 'Manage NuGet Packages...'
- install package
Siemens.Collaboration.Net.TiaPortal.AddIn.Build
and select a matching version (16.* = TIA Portal V16, 17.* = TIA Portal V17) - build your project
A reference to the assembly Siemens.Engineering.AddIn.dll
must be added to the project. This establishes the connection to the Openness API. The TIA Add-In Build Package automatically detects the TIA Portal installation and references the required references into the project.
In case the TIA Portal location can not be detected, define the property
TiaPortalLocation
the add-in project file (*.csproj). See Example for reference.
The TIA Add-In Build Package executes multiple build tasks before and after building the add-in project.
The EnsureEnvironment
task verifies that the correct target framework is configured for the Add-In project. TIA Add-Ins build for TIA Portal V16 should be built for .Net Framework 4.6.2, TIA Portal V17 for .Net Framework 4.8. If the wrong target framework configuration is detected the correct version will be set automatically.
This task can be disabled by setting
<EnsureEnvironmentTaskEnabled>false</EnsureEnvironmentTaskEnabled>
in the project file (*.csproj).
A simple add-in consists of at least the following two classes:
- View Provider: In this class, you define the areas in which the shortcut menu is to be displayed. For each area you have to program a separate provider, i.e. a separate class:
ProjectTreeAddInProvider
: Project treeGlobalLibraryTreeAddInProvider
: Global librariesProjectLibraryTreeAddInProvider
: Project libraryDevicesAndNetworksAddInProvider
: Hardware and network editor(not supported in this template)VciEditorAddInProvider
: Version Control Interface workspace
- Shortcut menu: This class contains the program code and defines the shortcut menu with its entries.
One or more view providers need to be inherited in order to be able to load the Add-In. Each view provider then provides one or more shortcut menu instances. Shortcut menu items are implemented in classes by inheriting the class ContextMenuAddIn
.
The TIA Add-In Build Package will deploy template implementations of the required classes if no implementation is detected.
This task can be disabled by setting
<TemplateTaskEnabled>false</TemplateTaskEnabled>
in the project file (*.csproj).
For the add-in to be recognized by the TIA Portal and displayed, the compiled assembly file (*.dll) must be converted to a file with the file extension ".addin". To do this the command-line program Siemens.Engineering.AddIn.Publisher.exe
that is available in the installation directory of the TIA Portal in the "PublicAPI" folder must be used.
To convert an assembly a configuration file is needed which provides all required information. This file is either created and preconfigured by the TIA Add-In Build Package (AddInPublisherConfiguration.xml
) or automatically detected in the project directory. The following settings of the configuration file will be maintained by the TIA Add-In Build Package:
- path of the assembly to be converted (FeatureAssembly)
- automatic detection of dependencies (AdditionalAssemblies)
- automatic detection of certificates in the project structure
- file version update
A post build event is automatically created to convert the assembly to an add-in. The converted add-in will be deployed alongside the assembly. If the build process is executed with elevated privileges the add-in is deployed in the TIA Portal Add-Ins directory as well.
Open the IDE (e.g. Microsoft Visual Studio) with admin privileges for automatic add-in deployment.
This task can be disabled by setting
<PublisherTaskEnabled>false</PublisherTaskEnabled>
in the project file (*.csproj).
TIA Add-Ins can easily be tested and debugged using the TIA Add-In Tester. The add-in templates already implement the required GetSelection
method to create a MenuSelectionProvider
selection. The deployment and debug configuration of the TIA Add-In Tester will be setup by this task. See TIA Add-In Tester for further information on how to debug and test a TIA Add-In.
This task can be disabled by setting
<DeployLaunchSettingsTaskEnabled>false</DeployLaunchSettingsTaskEnabled>
in the project file (*.csproj).
After all task have been completed the necessary changes are written to the files.
This task can be disabled by setting
<WriteChangesTaskEnabled>false</WriteChangesTaskEnabled>
in the project file (*.csproj).
All tasks can be disabled. Open the add-in project file (*.csproj) and set one of the following properties in a property group to disable it:
<EnsureEnvironmentTaskEnabled>false</EnsureEnvironmentTaskEnabled>
<TemplateTaskEnabled>false</TemplateTaskEnabled>
<PublisherTaskEnabled>false</PublisherTaskEnabled>
<DeployLaunchSettingsTaskEnabled>false</DeployLaunchSettingsTaskEnabled>
<WriteChangesTaskEnabled>false</WriteChangesTaskEnabled>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<EnsureEnvironmentTaskEnabled>false</EnsureEnvironmentTaskEnabled>
<TiaPortalLocation>F:\Software\TIA Portal V17</TiaPortalLocation>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Siemens.Collaboration.Net.TiaPortal.AddIn.Build" Version="17.*" />
</ItemGroup>
</Project>
The TIA Add-In Build Package adds several extension methods.
Get all devices in a project (iterates through devices, device groups and ungrouped devices recursively)
IEnumerable<Device> devices = tia.Projects.First().AllDevices()
Recursively get all device items of a device
IEnumerable<DeviceItem> deviceItems = myDevice.AllDeviceItems()
Get all device items with classification CPU in this project
IEnumerable<DeviceItem> cpus = project.AllCpus();
Get all PlcSoftware in the project
IEnumerable<PlcSoftware> plcSoftwares = project.AllPlcSoftware();
Get all SINAMICS Startdrive devices in the project
IEnumerable<Device> drives = project.AllStartdriveDevices();
Get all parents of an IEngineeringObject
IEnumerable<IEngineeringObject> parents = engineeringObject.Parents();
Get first parent of type Device
of an IEngineeringObject
Device device = engineeringObject.Parent<Device>();
Open a message box in foreground
var result = AddInMessageBox.Show("Successfully imported all files", "Import done", MessageBoxButton.OK, MessageBoxImage.Information);
Open a dialog in the foreground of the TIA Portal
var result = openFileDialog.ShowDialogInForeground();
Code and documentation copyright 2022 Siemens AG.
See LICENSE.md.