Skip to content

Step 2: Setup UA-ModelCompiler with Visual Studio

Last updated on April 10, 2022


This post shows how to setup the official UA-ModelCompiler with MS Visual Studio and to compile an executable binary to compile OPC UA ModelDesign files to OPC UA NodeSet files.

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


Alternative

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

Compile the ModelDesign file on Linux instead of MS Windows:
Setup ModelCompiler on Linux

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.

Contents

Install Visual Studio 2019

Info

An initial attempt with VS2017 failed. Use VS2019 or later.

Edit 2020-10-16: MS Visual Studio 2017 version 15.9.28, .NET framework version 4.8.04084 was reported to work in the comments.

Visual Studio Code can not compile solution projects without plugin. Prefer Visual Studio, which is a full IDE over Visual Studio Code, which is more of a featureful editor.

Install a recent version of Visual Studio Community Edition or better.

https://visualstudio.microsoft.com/de/downloads/

direct download link: https://visualstudio.microsoft.com/de/thank-you-downloading-visual-studio/?sku=Community

Follow the standard installation procedure.

Clone UA-ModelCompiler from Github

Note

You may use any Git-Client of your preference. This guide uses the official git command line client for windows (https://git-scm.com/download/win)

# johndoe@winpc MINGW64 /c/FLT_SW
git clone https://github.com/OPCFoundation/UA-ModelCompiler.git
cd UA-ModelCompiler
git checkout 8817477c7b481fd6eb6e9cccc05b76e83c7329ba
Notice Title

This commit was carefully chosen. It is the latest commit compatible with this tutorial. The master branch should be considered unstable.

Clone OPCFoundation UA-Nodeset submodule

UA-ModelCompiler uses the official OPC Foundation nodeset collection at https://github.com/OPCFoundation/UA-Nodeset as submodule. The ModelCompiler can be built without the submodule but having a rather complete collection of official UA-Nodesets available will come in handy when editing and compiling the ModelDesign file with Visual Studio 2019 later on.

To initialize the submodule, use the following command. This will also check out the referenced version:

# johndoe@winpc MINGW64 /c/FLT_SW/UA-ModelCompiler ((8817477...))
git submodule update --init --recursive

Open and compile UA-ModelCompiler with Visual Studio 2019

Start Visual Studio 2019

And open ModelCompiler Solution.sln from the folder created by git clone

You may get warning about unsupported or incompatible projects, as follows:

To fix this, you have to load both sub-projects of ModelCompiler Solution (see also https://developercommunity.visualstudio.com/content/problem/216061/project-incompatible-application-not-installed.html)

Configure the project to build in Release mode instead of the default Debug mode

You’re now ready to build UA-ModelCompiler. Watch the VS2019 output pane for success messages.

The output should look as follows:

1>------ Build started: Project: UA Core Library, Configuration: Release Any CPU ------
1>  UA Core Library -> C:\FLT_SW\UA-ModelCompiler\Bin\Release\Opc.Ua.ModelCompiler.Core.dll
2>------ Build started: Project: UA Model Compiler, Configuration: Release Any CPU ------
2>  UA Model Compiler -> C:\FLT_SW\UA-ModelCompiler\Bin\Release\Opc.Ua.ModelCompiler.exe
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The output shows, that the UA-ModelCompiler is stored at C:\FLT_SW\UA-ModelCompiler\Bin\Release\Opc.Ua.ModelCompiler.exe

Use PowerShell to execute Opc.Ua.ModelCompiler.exe without any arguments to get a small pop-up window with help information

# PS X:\>
cd C:\FLT_SW\UA-ModelCompiler\Bin\Release\

# PS C:\FLT_SW\UA-ModelCompiler\Bin\Release>
.\Opc.Ua.ModelCompiler.exe

The executable Opc.Ua.ModelCompiler.exe will be used to compile the OPC UA ModelDesign file to a OPC UA NodeSet and auxiliar files.

Published inInformation Modeling

10 Comments

  1. Marco D'Aurelio Marco D'Aurelio

    Hello,

    Many thanks for the comprehensive and detailed tutorial, I am finding it very useful in my journey into OPC UA.

    Just a notice: I was able to successfully compile UA-ModelCompiler with MS Visual Studio 2017 version 15.9.28, .NET framework version 4.8.04084.

    Best regards.

    • Benedict Simlinger Benedict Simlinger

      Thank you for your feedback. The post is updated accordingly.

  2. Steve Morris Steve Morris

    What am I missing? When I run the compiler I get the following error:

    E:\Projects\OPC_UA\UA-ModelCompiler\Bin\Release>.\Opc.Ua.ModelCompiler.exe -d2 E:\Projects\OPC_UA\FooFltModel_1\FooFltModel.xml -cg E:\Projects\OPC_UA\FooFltModel_1\FooFltModel.csv -o2 E:\Projects\OPC_UA\FooFltModel_1 -console
    Could not load resource ‘Opc.Ua.ModelCompiler.Design.BuiltInTypes.xml’.
    at Opc.Ua.Schema.SchemaValidator.LoadResource(Type type, String path, Assembly assembly) in E:\Projects\OPC_UA\UA-ModelCompiler\Core\Types\Schemas\SchemaValidator.cs:line 303
    at Opc.Ua.ModelCompiler.ModelCompilerValidator.LoadBuiltInModel() in E:\Projects\OPC_UA\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 800
    at Opc.Ua.ModelCompiler.ModelCompilerValidator.LoadBuiltInTypes() in E:\Projects\OPC_UA\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 101
    at Opc.Ua.ModelCompiler.ModelCompilerValidator.Validate2(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in E:\Projects\OPC_UA\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 972
    at Opc.Ua.ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion) in E:\Projects\OPC_UA\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 96
    at Opc.Ua.ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in E:\Projects\OPC_UA\UA-ModelCompiler\ModelCompiler\Program.cs:line 424

    I compiled UA-ModelCompiler from “git checkout 8817477c7b481fd6eb6e9cccc05b76e83c7329ba” with the latest version of MVC 2019 – VS 16.10.2

  3. Joe Joe

    Thanks for the tutorial! Very good.

    One question: Why is no executable version of the ModelCompiler available in the net? Everyone has to compile it’s own?

    • Benedict Simlinger Benedict Simlinger

      Hi Joe,

      I’m glad to hear that this tutorial is useful to you.

      Regarding your question:

      Have a look at the first article of this series over here:
      https://opcua.rocks/from-modelling-to-execution-opc-ua-information-model-tutorial/

      The figure captioned “Overview of available workflows and repository dependencies” shows that you can use a pre-built docker image on Linux. In fact, it’s recommended over building the ModelCompiler yourself, as indicated by the bold line and the text following that figure. Moreover, the official UA-ModelCompiler Github-Repository mentions said docker image in its README https://github.com/OPCFoundation/UA-ModelCompiler#docker-build although this docker image is not maintained by the OPC Foundation itself but by the owner of this blog.

      Hope that helps & all the best,
      Benedict

  4. Marcos Silva Santisteban Marcos Silva Santisteban

    Hi Folks.,

    I’ve tried with both versions of ModelCompiler
    download success…
    compiling success…
    executing failed…..

    C:\Users\zefsu\Documents\GitHub\desktop>git clone https://github.com/Pro/UA-ModelCompiler –recursive

    C:\Users\zefsu\Documents\GitHub\desktop>git clone https://github.com/OPCFoundation/UA-Nodeset –recursive

    Executing from PowerShell
    PS C:\Users\zefsu\Documents\GitHub\desktop\UA-ModelCompiler\build\bin\Release\net5.0> .\Opc.Ua.ModelCompiler.exe

    Instead of the Popup with the list of commands following text is being displayed:

    Usage: ModelCompiler [options] [command]

    Options:
    -?|-h|–help Show help information

    Commands:
    compile Takes an OPC UA ModelDesign file and generates a NodeSet and code for the .NETStandard stack.
    units Generates the OPC UA Engineering Units CSV from the official UNECE table of units.
    update-headers Updates all files in the output directory with the OPC Foundation MIT license header.

    Use “ModelCompiler [command] –help” for more information about a command.

    ………. The command –help displays the same texts.

    I’ve tried also to compile the ModelDesign.XML but it doesn’t recognize any online command.

    .\Opc.Ua.ModelCompiler.exe -d2 “.\Demo\ModelDesign.xml” -cg “.\Demo\ModelDesign.csv” -o “.\Demo”

    Would you please help me to go forwards, Best Regards, Marcos

    • Benedict Simlinger Benedict Simlinger

      Hi,

      the error messages indicate, that you should use the Opc.Ua.ModelCompiler.exe with the “compile” command, like

      Opc.Ua.ModelCompiler.exe [options] [command]

      • P W P W

        Hi Benedict and Marcos,

        I get the same text displayed in VS22 as Marcos. Entering the following command I´ll get an error:

        Command:
        .\Opc.Ua.ModelCompiler.exe compile -d2 .\Demo\example_project.xml -cg .\Demo\example_project.csv -o .\Demo

        Error:
        [UnregognizedCommandParsingException] Unrecognized option ‘-o’ (McMaster.Extensions.CommandLineUtils.CommandLineApplication)

        Can you help me with that issue?

        P W

        • Benedict Simlinger Benedict Simlinger

          Hi P W,

          I don’t have Opc.Ua.ModelCompiler.exe available for testing right now, so I can only help you with some guess work.

          Run
          Opc.Ua.ModelCompiler.exe compile --help
          or
          Opc.Ua.ModelCompiler.exe --help compile
          (I am not sure about the order of arguments)

          to figure out, why the ‘-o’ option is not accepted.

          On a hunch, maybe you want to use ‘-o2’ (output directory for multiple file output) instead of ‘-o’ (output directory for single file output).

          Let us know of your results & progress!

          Good luck & best wishes,
          Benedict

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.