Skip to content

Antlr4 tool jar file is not downloaded by Antlr4BuildTools when using NuGet Central Package Management and pinned version number #115

@RedFiveCode

Description

@RedFiveCode

Summary

When using NuGet Central Package Management with a pinned version number for the Antlr4.Runtime.Standard package, for example "[4.13.1]", the Antlr4BuildTools package is unable to download the Antlr4 tool jar file as expected. Consequently, the grammar file is not 'compiled' during the build and the build fails.

Introduction

When using NuGet Central Package Management, the Directory.Packages.props file contains the names and version numbers of each package.
This allows a centralised list of all the packages and their versions, and is useful for larger projects. The package version number can be set to a particular version, a minimum version, or a range of versions.

For example:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Antlr4BuildTasks" Version="[12.11.0]" />

    <!-- Don't use square brackets to pin version as this breaks Antlr4BuildTasks which attempts to read the Antlr4 version number,
         in turn this causes the build to fail as the classes auto-generated from the grammar file are not generated.
         Version="4.13.1"    works
         Version="[4.13.1]"  fails
    -->
    <!--<PackageVersion Include="Antlr4.Runtime.Standard" Version="4.13.1" />-->
    <PackageVersion Include="Antlr4.Runtime.Standard" Version="[4.13.1]" />
  </ItemGroup>
</Project>

The Antlr4BuildTools package looks for the version number of the Antlr4.Runtime.Standard package (so that it can download and run the appropriate tools for that version of Antlr4).

Failure case

When the Antlr4.Runtime.Standard package version is pinned to a specific version with square brackets,
for example "[4.13.1]", Antlr4BuildTools is unable to download the Antlr4 tool jar file during the build.

Image

The v2 match and v3 match are both empty.

Success cases

  • Don't use square brackets to pin the version number, for example "12.11.0"
  • Don't use Central Package Management, and instead specify the package version in the project file.
Image

The v3 match indicates the expected 4.13.1 version number.

Repo case

See the attached example project.
DemoApp.zip

Further reading:

https://learn.microsoft.com/en-us/nuget/concepts/package-versioning
https://stackoverflow.com/questions/79383712/central-package-management-version-pinning

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions