Skip to content

Build TwinCAT HMI project with command line

Following information can be used with:

  • VisualStudio 2013, 2015, 2017
  • TE2000-HMI-Engineering 1.10.*.* (Download)

One colleague has asked me this: ‘Chris, how to build a TwinCAT HMI (tchmi) project with command line?’. I guess several people out in the world just use scripts or automatic builds and will have the same question. Therefor, I like to give some hints where to look for internal information and how the task is done.

There should not be any problem to build our HMI project type with a command line or in Azure DevOps environments. It is only required to have an installed HMI, which provide relevant artifacts below “{{HARDDRIVE}}:\TwinCAT\Function” – but this can be changed dynamically during build-time as well. All information about parameters, settings, etc. can be found in the *.hmiproj-file. In a command line msbuild.exe will be used. For the call of “msbuild” you have to provide the parameters and settings manually, e.g “TcHmi_ProjectDirectory” in any *.hmiproj-file is mapped to “ProjectDirectory” which is required for the internal msbuild target implementations. Have a look, the mapping is like this:

<TcHmiMSBuild.Publish.TcHmiBuild 
  TaskAction="Build" 
  ProjectDirectory="$(TcHmi_ProjectDirectory)" 
  OutputPath="$(OutputPath)" 
  References="@(TcHmiReference)" />

An example for a msbuild-call is:

$$ msbuild "C:\temp\TcHmiProject1" -t:TcHmiProject1 
  -p:TcHmi_ProjectDirectory="C:\temp\TcHmiProject1\TcHmiProject1" 
  -p:TcHmi_ServerAddress="127.0.0.1" -p:TcHmi_ServerPort=3000 
  -p:Configuration=Release -p:Platform="TwinCAT HMI" -verbosity:m

Hint: You can change the mapping, i.e. “TcHmi_ProjectDirectory” can be changed to “MickeyMouseDirectoryName”, but you have to do this in any HMI project file.

The msbuild call looks like this:

The result will be:

The mentioned directory “{{HARDDRIVE}}:\TwinCAT\Function” which is mapped to an HMI-installation can be changed but you have to edit the HMI-project file. In short, the imported lines are in the first rows:

[..]
<TcHmiDirectory>
  $(registry:HKEY_LOCAL_MACHINE\Software\Beckhoff\TwinCAT3\3.1@InstallDir)\..\Functions\TE2000-HMI-Engineering
</TcHmiDirectory>
<TcHmiDirectory Condition="'$(TcHmiDirectory)'==''">
  $(registry:HKEY_LOCAL_MACHINE\Software\Wow6432Node\Beckhoff\TwinCAT3\3.1@InstallDir)\..\Functions\TE2000-HMI-Engineering
</TcHmiDirectory>
[..]

We fill “TcHmiDirectory” automatically with registry information of an installed TwinCAT. Here, probably you can add a condition like:

[..]
<TcHmiDirectory>$(MYOWNLOCAL_INSTALL_DIR)</TcHmiDirectory>
<TcHmiDirectory Condition="'$(TcHmiDirectory)'==''">
  $(registry:HKEY_LOCAL_MACHINE\Software\Beckhoff\TwinCAT3\3.1@InstallDir)\..\Functions\TE2000-HMI-Engineering
</TcHmiDirectory>
<TcHmiDirectory Condition="'$(TcHmiDirectory)'==''">
  $(registry:HKEY_LOCAL_MACHINE\Software\Wow6432Node\Beckhoff\TwinCAT3\3.1@InstallDir)\..\Functions\TE2000-HMI-Engineering
</TcHmiDirectory>
[..]

During the call of msbuild you can set the directory which link to the installation directory in your devops environment, e.g.

$$ msbuild "C:\temp\TcHmiProject1" -t:TcHmiProject1 
  –p:MYOWNLOCAL_INSTALL_DIR=”Z:\azuredevops\agent\s\0\twincathmi\te2000-artifacts” 
  -p:TcHmi_ProjectDirectory="C:\temp\TcHmiProject1\TcHmiProject1" 
  -p:TcHmi_ServerAddress="127.0.0.1" -p:TcHmi_ServerPort=3000 
  -p:Configuration=Release -p:Platform="TwinCAT HMI" -verbosity:m

Azure DevOps’ configuration pages allow to set these parameters.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.