I'm using unit tests with my ANTLR3-generated parser project to verify my grammar definition. I just downloaded NCrunch to trial its use as well, but it seems to have some problems with ANTLR3.
In order to get ANTLR builds working at all, I first needed to add the grammar file (.g3) and the ANTLR directory (../Reference/**.*) to "Additional files to include" for the parser project. Now, builds work
sometimes: generally, it seems to work when I first start Visual Studio, and often starts to fail when I'm editing the grammar file, but doesn't usually recover from that even after I'm done editing and can run unit tests manually through Test Explorer.
The error I get from NCrunch for the build is rather opaque:
Quote:..\Reference\Antlr\Antlr3.targets (126)#0: Unknown build error: : error 10 : internal error: {my grammar file}.g3 : System.InvalidCastException: Unable to cast object of type 'Antlr3.Targets.CSharp3Target' to type 'Antlr3.Codegen.Target'. at Antlr3.Codegen.CodeGenerator.LoadLanguageTarget(String language, String targetsDirectory) in j:\dev\github\sharwell\antlrcs\Antlr3\Codegen\CodeGenerator.cs:line 358 at Antlr3.Tool.Grammar..ctor(AntlrTool tool, String fileName, CompositeGrammar composite) in j:\dev\github\sharwell\antlrcs\Antlr3\Tool\Grammar.cs:line 585 at Antlr3.AntlrTool.GetRootGrammar(String grammarFileName) in j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:line 776 at Antlr3.AntlrTool.Process() in j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:line 624 LoadLanguageTarget at offset 344 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\Codegen\CodeGenerator.cs:358:21 .ctor at offset 932 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\Tool\Grammar.cs:585:13 GetRootGrammar at offset 59 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:776:13 Process at offset 398 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:624:21
This is rather weird in that Antlr3.Targets.CSharp3Target is derived from Antlr3.Codegen.Target, so it should be possible to cast in that direction. The line 126 on Antlr3.targets is the AntlrClassGenerationTask, but I don't see anything wrong with it (plus, the project builds ok in Visual Studio and when I run it through MSBuild).
Does anyone have any ideas what could be different between the way VS2012 and NCrunch builds the software that could cause this error?
Edit: Oops, forgot to mention tools' versions. NCrunch 1.45.0.12, antlr-dotnet-tool-3.5.0.2, and Visual Studio 2012.