Skip to content

Step 2: Setup UA-ModelCompiler in Linux

Last updated on April 10, 2022


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

5 Comments

  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

  2. Siegfried Gipp Siegfried Gipp

    Hi,
    i’m currently trying this step 2. I managed to install the correct version of mono in my Linux VM, and got nuget.exe. Now when i try to build the model compiler, i first get a warning from every package in packages.config, then an error of every package.
    The warnings are like:

    Restoring NuGet package Csv.2.0.62.
    WARNING: Unable to find version ‘2.0.62’ of package ‘Csv’.
    https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
    GSSAPI operation failed with error – An invalid name was supplied (Configuration file does not specify default realm).

    Then the error messages are like:
    Unable to find version ‘2.0.62’ of package ‘Csv’.
    https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
    GSSAPI operation failed with error – An invalid name was supplied (Configuration file does not specify default realm).

    I can download the https://api.nuget.org/v3/index.json file though. So i doubt that this is a permission problem. It seems to be something different.

  3. Daniel Daniel

    When running “msbuild “ModelCompiler Solution.sln” /p:TargetFrameworkVersion=”v4.5″“ I get the following error:

    icrosoft (R) Build Engine version 16.6.0 for Mono
    Copyright (C) Microsoft Corporation. All rights reserved.

    Building the projects in this solution one at a time. To enable parallel build, please add the “-m” switch.
    Build started 12/07/2021 17:32:19.
    Project “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” on node 1 (default targets).
    ValidateSolutionConfiguration:
    Building solution configuration “Debug|Mixed Platforms”.
    Project “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” (1) is building “/home/root/UA-ModelCompiler/Tests/DemoModel/DemoModel.csproj” (2) on node 1 (default targets).
    /usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file ‘/home/root/UA-ModelCompiler/Tests/DemoModel/obj/project.assets.json’ not found. Run a NuGet package restore to generate this file. [/home/root/UA-ModelCompiler/Tests/DemoModel/DemoModel.csproj]
    Done Building Project “/home/root/UA-ModelCompiler/Tests/DemoModel/DemoModel.csproj” (default targets) — FAILED.
    Project “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” (1) is building “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (3) on node 1 (default targets).
    Project “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (3) is building “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (3:2) on node 1 (Build target(s)).
    /usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file ‘/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/obj/project.assets.json’ not found. Run a NuGet package restore to generate this file. [/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj]
    Done Building Project “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (Build target(s)) — FAILED.
    Done Building Project “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (default targets) — FAILED.
    Done Building Project “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” (default targets) — FAILED.

    Build FAILED.

    “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” (default target) (1) ->
    “/home/root/UA-ModelCompiler/Tests/DemoModel/DemoModel.csproj” (default target) (2) ->
    (ResolvePackageAssets target) ->
    /usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file ‘/home/root/UA-ModelCompiler/Tests/DemoModel/obj/project.assets.json’ not found. Run a NuGet package restore to generate this file. [/home/root/UA-ModelCompiler/Tests/DemoModel/DemoModel.csproj]

    “/home/root/UA-ModelCompiler/ModelCompiler Solution.sln” (default target) (1) ->
    “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (default target) (3) ->
    “/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj” (Build target) (3:2) ->
    /usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1004: Assets file ‘/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/obj/project.assets.json’ not found. Run a NuGet package restore to generate this file. [/home/root/UA-ModelCompiler/Opc.Ua.ModelCompiler/Opc.Ua.ModelCompiler.csproj]

    0 Warning(s)
    2 Error(s)

    Time Elapsed 00:00:00.80

Leave a Reply

Your email address will not be published.

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