Antlr4ClassGenerationTask and C# ANTLR4 Build problems

1,080 views
Skip to first unread message

Robert Eberhart

unread,
May 31, 2013, 11:22:34 AM5/31/13
to antlr-di...@googlegroups.com
Hello,

I'm trying to get started on a project using ANTLR4 and I'm a completely new to this so please excuse me fumbling around.

The project at the moment is a bare bones C# windows forms application and configured per the instructions at GitHub (https://github.com/sharwell/antlr4cs).  At this point, the project will compile.

I added the sample grammar using the ANTLR 4 Combined Grammar.  At this point, the build fails with the following error:

Error 1 The "Antlr4ClassGenerationTask" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory. C:\projects\OracleForms\OracleFormsParse\libraries\Antlr4\Antlr4.targets 129 5 OracleFormsParse.WindowsApplication

Looking at the output from MSBUILD, we have the following:

Building target "Antlr4Compile" completely.
Output file "obj\x86\Debug\OracleFormsParse.WindowsApplication.csproj.Antlr4GeneratedCodeFileListAbsolute.txt" does not exist.
C:\projects\OracleForms\OracleFormsParse\libraries\Antlr4\Antlr4.targets(129,5): error MSB4036: The "Antlr4ClassGenerationTask" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.
Done building target "Antlr4Compile" in project "OracleFormsParse.WindowsApplication.csproj" -- FAILED.

Based on this output, the csproj file is configured correctly because it's able to find the Antlr4.targets file.  Look at the file and the line indicated by the error, the Antlr4ClassGenerationTask is defined there, but I'm not sure what the issue is.

Would anyone have any further information on what might be causing this error?

- Robert Eberhart

Sam Harwell

unread,
May 31, 2013, 11:30:59 AM5/31/13
to antlr-di...@googlegroups.com

Hi Roger,

 

Can you include a copy of your .csproj file so I can compare it with mine?

 

Thank you,

--

Sam Harwell

Owner, Lead Developer

http://tunnelvisionlabs.com

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Robert Eberhart

unread,
May 31, 2013, 11:42:34 AM5/31/13
to antlr-di...@googlegroups.com
Sorry about cutting and pasting, but my company has us locked down on Google Docs.  Thank you for taking a look at this.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{597CF6BB-AC91-42C2-839E-D366FB05BDB1}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>OracleFormsParse.WindowsApplication</RootNamespace>
    <AssemblyName>OracleFormsParse.WindowsApplication</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Antlr4.Runtime.v4.0">
      <HintPath>..\..\libraries\Antlr4\Antlr4.Runtime.v4.0.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="OracleSQL.g4.lexer.cs">
      <DependentUpon>OracleSQL.g4</DependentUpon>
    </Compile>
    <Compile Include="OracleSQL.g4.parser.cs">
      <DependentUpon>OracleSQL.g4</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Antlr4 Include="OracleSQL.g4">
      <Generator>MSBuild:Compile</Generator>
      <CustomToolNamespace>OracleFormsParse.WindowsApplication</CustomToolNamespace>
    </Antlr4>
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <PropertyGroup>
    <!-- Folder containing Antlr4BuildTasks.dll -->
    <Antlr4BuildTaskPath>$(ProjectDir)..\libraries\Antlr4</Antlr4BuildTaskPath>
    <!-- Path to the ANTLR Tool itself. -->
    <Antlr4ToolPath>$(ProjectDir)..\..\libraries\Antlr4\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolPath>
  </PropertyGroup>
  <Import Project="$(ProjectDir)..\..\libraries\Antlr4\Antlr4.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Robert Eberhart

unread,
May 31, 2013, 11:45:25 AM5/31/13
to antlr-di...@googlegroups.com
Actually, taking a look at it again, revealed the problem.

 <Antlr4BuildTaskPath>$(ProjectDir)..\libraries\Antlr4</Antlr4BuildTaskPath>

I'm two levels up - not one.  So, to fix I had to change to:

 <Antlr4BuildTaskPath>$(ProjectDir)..\..\libraries\Antlr4</Antlr4BuildTaskPath>

Oops.  Sorry about that.

- Robert Eberhart

Sam Harwell

unread,
Jun 5, 2013, 4:26:19 PM6/5/13
to antlr-di...@googlegroups.com

Glad it’s fixed. Hopefully the rest falls in line as well. :)

 

If you aren’t already using the latest Visual Studio extension for ANTLR 4, you can get it here. This extension will automatically configure a grammar file properly when you add it to your project. In particular, ANTLR 4 requires the tool to specify the “Custom Tool Namespace” for generated code in the Visual Studio Properties pane for the file. This extension configures that setting automatically, and extends the properties pane as shown below for easy customization of some additional grammar build options.

 

http://visualstudiogallery.msdn.microsoft.com/25b991db-befd-441b-b23b-bb5f8d07ee9f

 

--

Sam Harwell

Owner, Lead Developer

http://tunnelvisionlabs.com

 

--

mll...@rarediseases.org

unread,
Jun 14, 2013, 12:44:12 PM6/14/13
to antlr-di...@googlegroups.com
Hello,
I recently cloned the antlr4cs repo and am trying to build the antlr4 solution. the runtime and buildtasks projects all build fine but the test projects all fail. here is the output from the build:
****************************

1>------ Rebuild All started: Project: Antlr4.Runtime.v4.5, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: Antlr4.Runtime.v4.0, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: Antlr4.Runtime.v3.5, Configuration: Debug Any CPU ------
4>------ Rebuild All started: Project: Antlr4.Runtime.v3.0, Configuration: Debug Any CPU ------
1> Antlr4.Runtime.v4.5 -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\v4.5\Debug\Antlr4.Runtime.v4.5.dll
2> Antlr4.Runtime.v4.0 -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\v4.0\Debug\Antlr4.Runtime.v4.0.dll
3> Antlr4.Runtime.v3.5 -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\v3.5\Debug\Antlr4.Runtime.v3.5.dll
5>------ Rebuild All started: Project: Antlr4.Runtime.v2.0, Configuration: Debug Any CPU ------
6>------ Rebuild All started: Project: Antlr4.Runtime.Portable, Configuration: Debug Any CPU ------
4> Antlr4.Runtime.v3.0 -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\v3.0\Debug\Antlr4.Runtime.v3.0.dll
7>------ Rebuild All started: Project: Antlr4.Runtime.Test.v4.5, Configuration: Debug Any CPU ------
8>------ Rebuild All started: Project: Antlr4BuildTasks.v4.0, Configuration: Debug Any CPU ------
8> Antlr4BuildTasks.v4.0 -> G:\antlr4cs\runtime\CSharp\Antlr4BuildTasks\bin\v4.0\Debug\Antlr4BuildTasks.v4.0.dll
6> Antlr4.Runtime.Portable -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\Portable\Debug\Antlr4.Runtime.Portable.dll
9>------ Rebuild All started: Project: Antlr4.Runtime.Test.v4.0, Configuration: Debug Any CPU ------
5> Antlr4.Runtime.v2.0 -> G:\antlr4cs\runtime\CSharp\Antlr4.Runtime\bin\v2.0\Debug\Antlr4.Runtime.v2.0.dll
10>------ Rebuild All started: Project: Antlr4.Runtime.Test.v3.5, Configuration: Debug Any CPU ------
11>------ Rebuild All started: Project: Antlr4.Runtime.Test.v3.0, Configuration: Debug Any CPU ------
9>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
7>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
12>------ Rebuild All started: Project: Antlr4.Runtime.Test.v2.0, Configuration: Debug Any CPU ------
11>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
13>------ Rebuild All started: Project: Antlr4.Runtime.Test.Portable, Configuration: Debug Any CPU ------
10>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
14>------ Rebuild All started: Project: Antlr4BuildTasks.v3.5, Configuration: Debug Any CPU ------
12>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
13>G:\antlr4cs\runtime\CSharp\build\Antlr4.targets(129,5): error AC1000: Unknown build error: Object reference not set to an instance of an object.
14> Antlr4BuildTasks.v3.5 -> G:\antlr4cs\runtime\CSharp\Antlr4BuildTasks\bin\v3.5\Debug\Antlr4BuildTasks.v3.5.dll
========== Rebuild All: 8 succeeded, 6 failed, 0 skipped ==========

****************************
Can anyone shed some light on this for me?

thank you!!!

Sam Harwell

unread,
Jun 14, 2013, 1:23:59 PM6/14/13
to antlr-di...@googlegroups.com
One copy of the ANTLR build task binaries is included in source control (in the runtime/CSharp/build folder). This binary hasn't been updated since issue #2 was fixed:
https://github.com/sharwell/antlr4cs/issues/2

To get things working in the meantime, if you are running 64-bit Windows then you should make sure you have a copy of both the 32- and 64-bit versions of Java installed.

You can also report this (out of date bootstrap binaries) as an issue here:
https://github.com/sharwell/antlr4cs/issues

Thank you,
--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com

-----Original Message-----
From: antlr-di...@googlegroups.com [mailto:antlr-di...@googlegroups.com] On Behalf Of mll...@rarediseases.org
Sent: Friday, June 14, 2013 11:44 AM
To: antlr-di...@googlegroups.com

mll...@rarediseases.org

unread,
Jun 14, 2013, 2:18:32 PM6/14/13
to antlr-di...@googlegroups.com
Sam,
thank you for the prompt response!

I've installed the 32bit java and the build completed without errors. :) I received a number of "empty switch block" warnings on the generated lexers and a few multiple definition warnings on the predefined type 'System.Runtime.CompilerServices.ExtensionAttribute'; 14 warnings in total, but no errors.

earlier today while looking for answers I came upon a thread suggesting that ReSharper was causing problems in this context so I removed ReSharper; is the "ReSharper issue" valid? i.e. should I leave ReSharper out or can I put it back in? I was using the latest release (7.x?).

thank you for all of your work; I simply LOVE AntlrWorks - while I [still] remember the days of lexx and yacc I sure don't pine for them. ANTLR is incredible and AntlrWorks makes using it a joy.... :)

-mark

Sam Harwell

unread,
Jun 14, 2013, 2:28:34 PM6/14/13
to antlr-di...@googlegroups.com
I don't use ReSharper, so I can't tell you whether or not a particular current version will work properly with the ANTLR .targets file. Some of the warnings you received are due to restrictions on the target framework version used in the test projects. As long as you use the runtime library corresponding to the framework version you are actually using, you shouldn't have a problem.

I'm glad to hear the tools are working out for you. As a heads-up, the ANTLR language support extension for Visual Studio 2010 and 2012 will help you will some of the tasks required for working with ANTLR 4 grammars in C#. This includes automatically configuring the namespace the lexers/parsers are generated in, providing file templates for adding new grammars to your project, and configuring the listener and visitor generation options on a per-grammar basis in the Properties Pane. At this time, syntax highlighting is provided for ANTLR 4 grammars but the IntelliSense support has not yet been updated to the same caliber as ANTLRWorks 2.
http://visualstudiogallery.msdn.microsoft.com/25b991db-befd-441b-b23b-bb5f8d07ee9f

Thank you,
--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com

-----Original Message-----
From: antlr-di...@googlegroups.com [mailto:antlr-di...@googlegroups.com] On Behalf Of mll...@rarediseases.org
Reply all
Reply to author
Forward
0 new messages