Antlr4 C# targets and output path of generated files

泪湿孤枕 提交于 2019-12-02 23:50:31

You are encountering a known bug with ReSharper. The ANTLR 3 and ANTLR 4 C# build integration is reliable, and uses long-established patterns that Microsoft uses with other languages and code generation tasks. Your options are:

  1. Stop using ReSharper
  2. Get the ReSharper authors to address the lack of support for this feature, or
  3. Modify the ANTLR 4 target to work around the limitation in ReSharper, which will introduce other problems into the build which may or may not be acceptable for your use.

Option 1 is certainly the least expensive, and most likely to provide reliable long-term support for your projects.

I found an extension for Resharper: ReSharper.ExternalCode.

Tip for Antlr: add obj\Debug in Resharper -> Code Inspection -> External Code and reload solution.

It's works for me.

There is an easy way to get the best of both Antlr 4 and Visual Studio. You are on the right track in having a separate grammar project and implementation project, but you are missing a couple steps.

Follow these steps to get the Intellisense working

  • In Visual Studio, go to Tools -> Extensions and Updates and search the Online section for "ANTLR Language Support" by Sam Harwell.
    • This does a few things:
      • Adds Templates for the combined grammars.
      • Adds Syntax Highlighting
      • Adds an MSBuild target for the grammar to generate the parser.
  • In your solution, set up your project structure like this:
    • Solution
      • Grammar Project
        • ANTLR 4 Combined Grammar
      • Implementation Project
        • Folder for Links to Generated files
        • Listener Implementation Class
  • Write and Compile your grammar.
  • In your folder for the Links to Generated Files, Right-Click the folder and click Add -> Existing Item
  • Browse to Grammar Project\obj\Debug and select all the generated parser files.
  • This next step is important. On the Add button there is a little drop-down arrow. Click the drop-down arrow and click "Add As Link".
    • This will add the generated files to the implementation project using a symbolic link instead of a direct copy.
    • This gives the added benefit of not having to remove and re-add the parser files if you have to change your grammar later.
  • Intellisense should work now for your generated parser classes, and you don't even have to disable ReSharper.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!