TritonMate Words: Compile with ANTLR on Linux/Mono

It is fairly easy to compile #SNMP 7.5 on Windows, as the ANTLR C# runtime contains a MSBuild targets file which provides good enough integration. However, due to a Mono bug, this targets file cannot be loaded by xbuild. Thus, if you download #SNMP 7.5 source code and want to compile it on Linux, you find that it is impossible.

So how to fix this if I could not resolve the Mono bug? Well, we need to find another way to compile the grammar file,

  1. Remove .
  2. Add to exec Antlr3.exe on Mono. This compiles Smi.g to SmiLexer.cs and SmiParser.cs.
  3. Include the generated files in the project.

To achieve better cross platform compatibility, we don’t need to really perform the above steps on SharpSnmpLib.AST.csproj, but use a few Condition test, as demonstrated in this change set,

In this way, we can still use ANTLR targets on Windows, while switching to ANTLR3 compilation on Linux/Mono. I don’t plan to do anything further here, as mainly the development is on Windows.

Unfortunately, this only fixes the ANTLR compilation issue, while NuGet is another silly piece that fails to work on Mono, and when I tried to fix it a bug occurred.

Let’s see if those Microsoft guys can fix it sooner.

This NuGet bug prevents NuGet packages from being restored, so if you want to compile latest #SNMP code base on Linux, you can grab the packages folder from

Decompress it, and then put the packages folder in the correct place. After that, the remaining steps are documented in KB600006 and KB600007.

I am going to receive my new laptop tomorrow. The development of TritonMate will be reactivated in a couple of hours.

Stay tuned.

© Lex Li. All rights reserved. The code included is licensed under CC BY 4.0 unless otherwise noted.

© - Lex Li. All rights reserved.

Using the Chirpy theme for Jekyll.

Last updated on April 13, 2024