tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.Net Core Support

ryanlin1986 opened this issue · comments

Nuget error when installing for .Net Core console app:
Errors in c:\users\ryanl\documents\visual studio 2015\Projects\ConsoleApp2\src\ConsoleApp2\ConsoleApp2.xproj
Package Antlr4.Runtime 4.5.3-rc1 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Antlr4.Runtime 4.5.3-rc1 supports:
- net20 (.NETFramework,Version=v2.0)
- net30 (.NETFramework,Version=v3.0)
- net35-cf (.NETFramework,Version=v3.5,Profile=CompactFramework)
- net35-client (.NETFramework,Version=v3.5,Profile=Client)
- net40-client (.NETFramework,Version=v4.0,Profile=Client)
- net45 (.NETFramework,Version=v4.5)
- netcore45 (.NETCore,Version=v4.5)
- portable-net40+sl5+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile328)

commented

The Antlr4.Runtime package can already be used with .NET Core projects, try a project file such as the following. The important part is adding an import that is supported by the Antlr4.Runtime package, such as "imports": "net45"

{
  "version": "1.0.0-*",

  "dependencies": {
    "Antlr4.Runtime": "4.5.3-rc1",
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }
}

Obviously, I haven't been able to get the compile tools running in the Antlr4 package nicely, but as a workaround, I simply downloaded the antlr4.runtime.4.5.3-rc1.nupkg package from nuget and extracted the file antlr4-csharp-4.5.3-SNAPSHOT-complete.jar to my project root. I then added a batch script that would run the generator.

DEL /Q /S Generated
java -jar antlr4-csharp-4.5.3-SNAPSHOT-complete.jar *.g4 -o Generated -Dlanguage=CSharp_v4_5 -package "MyNamespace" -visitor

So, whenever I make changes to my .g4 files, I just run the script, which deletes and re-generates the .cs files for me.

Note, I had to use the jar file from the nuget package as I wasnt able to use this method with the antlr-4.3-complete.jar download from the http://www.antlr.org/ website, due to subtle differences between the code generated by that version and the Antlr4.Runtime package.