Net4x.AntlrPostBuild 1.0.0.26245

dotnet add package Net4x.AntlrPostBuild --version 1.0.0.26245
                    
NuGet\Install-Package Net4x.AntlrPostBuild -Version 1.0.0.26245
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net4x.AntlrPostBuild" Version="1.0.0.26245" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.AntlrPostBuild" Version="1.0.0.26245" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.AntlrPostBuild" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net4x.AntlrPostBuild --version 1.0.0.26245
                    
#r "nuget: Net4x.AntlrPostBuild, 1.0.0.26245"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Net4x.AntlrPostBuild@1.0.0.26245
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net4x.AntlrPostBuild&version=1.0.0.26245
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.AntlrPostBuild&version=1.0.0.26245
                    
Install as a Cake Tool

Net4x.AntlrPostBuild

A build-only MSBuild tool that post-processes ANTLR-generated C# sources so that one set of generated files compiles against both ANTLR C# runtimes:

  • Antlr4.Runtime.Standard — the modern runtime used on .NET Standard / .NET (Core), and
  • Antlr4.Runtime — the legacy runtime used on .NET Framework 3.5 / 4.0, which is built on Sharpen and exposes a different API for a handful of members.

Instead of maintaining two copies of a generated lexer/parser, the tool rewrites the few lines that differ into #if NETSTANDARD / #else blocks, and writes the result into the parser project.

Install

dotnet add package Net4x.AntlrPostBuild

The package contains no assemblies to reference — it ships an MSBuild .targets file plus the tool itself under native/. Mark it as a build-only dependency:

<PackageReference Include="Net4x.AntlrPostBuild" Version="1.0.*" PrivateAssets="All" />

Net4x.AntlrPostBuild.targets is imported automatically and adds two targets that run AfterTargets="PostBuildEvent" — PrepareParser on Windows (runs AntlrPostBuild.exe) and UnixPrepareParser elsewhere (runs dotnet AntlrPostBuild.dll). Both pass the consuming project's directory as -ProjectDir:.

What it rewrites

Each rule matches a line by substring and replaces that whole line with a conditional block:

Generated code Rewritten to (non-NETSTANDARD branch)
public override int[] SerializedAtn { get { return _serializedATN; } } public override string SerializedAtn returning JsonConvert.SerializeObject(_serializedATN)
new ATNDeserializer().Deserialize(_serializedATN); new ATNDeserializer().Deserialize(Array.ConvertAll(_serializedATN, i => (char)i))
var charStream = CharStreams.fromString(script); CharStreams.fromStream(new MemoryStream(Encoding.UTF8.GetBytes(script)))
this.TokenFactory.Create(new Tuple<ITokenSource, ICharStream>(…), MySQLLexer.DOT_SYMBOL, … the same call using Antlr4.Runtime.Sharpen.Tuple<…>

The NETSTANDARD branch always keeps the original generated line, so the modern runtime path is unchanged. Files are otherwise copied verbatim.

Note that rewritten files are written with CRLF line endings (the injected blocks are CRLF, and a file that matches more than the last rule is normalised to CRLF throughout). Files with no match are copied through byte for byte. If your repository enforces LF, add the output directory to .gitattributes accordingly.

Because the legacy branch uses Newtonsoft.Json, MemoryStream and Encoding, the target project must reference Newtonsoft.Json and have System.IO / System.Text in scope for the old targets.

Expected layout

The tool is built for a specific solution shape. Given -ProjectDir:<dir> it:

  1. reads every *.cs in <dir>\Antlr (the ANTLR-generated output);
  2. adds the runtime base classes from <dir>\..\grammars-v4\sql\...\CSharp\ — PlSqlLexerBase, PlSqlParserBase, MySqlLexerBase, MySqlParserBase, SqlMode, SqlModes, PostgreSQLLexerBase, PostgreSQLParserBase, LexerDispatchingErrorListener, ParserDispatchingErrorListener;
  3. deletes every *.cs in <dir>\..\SqlParameterizer.Parser\Antlr (creating the directory if needed);
  4. writes the rewritten files there under their original names.
<solution>\
  <your project>\Antlr\          <- input:  ANTLR-generated .cs
  grammars-v4\sql\...\CSharp\    <- input:  hand-written runtime base classes
  SqlParameterizer.Parser\Antlr\ <- output: cleared, then rewritten copies

⚠️ Step 3 is destructive. The output directory is treated as generated: do not keep hand-written sources in SqlParameterizer.Parser\Antlr.

If an expected base-class file is missing, the tool throws and the build fails.

Command line

AntlrPostBuild -ProjectDir:"<path>" [-Configuration:"<cfg>"]
  • -ProjectDir: — required; surrounding single or double quotes are trimmed. Without it the tool prints ProjectDir argument is required. and exits with -1.
  • -Configuration: — accepted for compatibility and currently ignored.

Exit codes: 0 on success, -1 if the argument is missing, the input directory does not exist, or a stale output file could not be deleted.

Requirements

  • The tool itself runs on .NET 10 (native/AntlrPostBuild.exe on Windows, dotnet native/AntlrPostBuild.dll elsewhere).
  • The consuming project can target anything; the package is net35;net40;netstandard2.0;net10.0 compatible and contributes no runtime assemblies.

License / source

Source: https://bitbucket.org/piero-viano/antlrpostbuild

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.26245 93 9/3/2026
1.0.0 212 11/27/2025