Skip to content

Step 2: Setup UA-ModelCompiler in Linux

Last updated on October 15, 2020


Setup the UA-ModelCompiler on Linux to compile ModelDesign files to UANodeSet files.

This Post is part of the OPC UA Information Model Tutorial.


Alternative

Instead of compiling ModelDesign files on Linux, the following alternative workflows are available:

Compile the ModelDesign file on MS Windows (Setup UA-ModelCompiler on Windows)

Instead of editing ModelDesign files and compiling them into UANodeSet files, edit of UANodeSet files directly with appropriate editors: Setup NodeSet Editor

Recommendation

This guide strongly recommends editing and compiling ModelDesign files over direct editing of UANodeSet files. Although ModelDesign files are not part of the OPC UA standard (UANodeSet are part of the standard) they are part of the toolchain used by the OPC Foundation to generate official UANodeSet files. Following the example set by the OPC Foundation will result in a more sustainable, reproducible and stable workflow overall.

Using a Docker Container

If you are on Linux, I strongly recommend to use the precompiled docker container available on DockerHub: https://hub.docker.com/r/sailavid/ua-modelcompiler

git clone https://github.com/Pro/opcua-animal-cs
cd opcua-animal-cs
docker run \
	  --mount type=bind,source=$(pwd),target=/model/src \
	  --entrypoint "/app/PublishModel.sh" \
	  sailavid/ua-modelcompiler:opcua_rocks_tested \
	   /model/src/animalModel animal /model/src/Published

This will build the model and copy it into opcua-animal-cs/Published/animal:

  • animal.Classes.cs
  • animal.Constants.cs
  • animal.DataTypes.cs
  • animalModel.csv
  • animalModel.xml
  • animal.NodeSet2.xml
  • animal.NodeSet.xml
  • animal.PredefinedNodes.uanodes
  • animal.PredefinedNodes.xml
  • animal.Types.xsd
  • animal.Types.bsd

Compile the Model Compiler on Linux

Instead of using the pre-compiled docker container, you can also clone the official UA-ModelCompiler repository and build the C# code using mono:

git clone https://github.com/OPCFoundation/UA-ModelCompiler.git
cd UA-ModelCompiler

Install mono and nuget:

sudo apt install mono-devel mono-complete
cd UA-ModelCompiler
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
mono nuget.exe install -OutputDirectory packages ModelCompiler/packages.config

Then you can build the ModelCompiler using mono, which will create a .exe file that can be executed on linux (Bin/Debug/Opc.Ua.ModelCompiler.exe)

msbuild "ModelCompiler Solution.sln" /p:TargetFrameworkVersion="v4.5"
Error during compilation?

If you get the following error “Could not resolve type with token 01000195”, then you probably need to update your mono installation (see comments below).

I strongly recommend to use the provided PublishModel.sh script here:

https://github.com/Pro/opcua-animal-cs/blob/master/PublishModel.sh

This gives you a simpler interface to the model compiler:

./PublishModel.sh $DIR/animalModel animal $DIR/Published

The first argument is the path to the ModelDesign xml file, without extension. The second argument is the prefix for the generated NodeSet2 files. The last argument is the output directory.

Example usage is shown here:

https://github.com/Pro/opcua-animal-cs/blob/master/build_model.sh

Published inInformation Modeling

One Comment

  1. Marco Kreft Marco Kreft

    Hi,
    thanks for this tutorial. I havent finished it jet but it seems all in all very helpful!
    I just want to leave a quick hint on the “mono nuget.exe install -OutputDirectory packages ModelCompiler/packages.config” command from above:
    – there I was getting the error “Could not resolve type with token 01000195”.
    I found the solution by updating mono to the latest version via: https://www.mono-project.com/download/stable/#download-lin-ubuntu. This might seem redundant to some folks but since it wasnt to me there might be the chance that some else will find it helpful to know 🙂

    Thank you again for all the hard work.

    Cheers,
    Marco

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.