use*_*002 2 c# antlr4 visual-studio-2019
我正在尝试让antlr在VS中工作。我\xe2\x80\x99已经很长时间没有接触VS了。我已经根据 Antlr 在线文档添加了 AntlrVSIX 扩展,这为我创建了一个示例计算器项目,但我无法编译它(我卸载并重新安装了 AntlrVSIX,但它对以下问题没有影响)。
\nVS 抱怨 \xe2\x80\x9c 找不到类型或命名空间名称“Antlr4”(您是否缺少 using 指令或程序集引用?)\xe2\x80\x9d 并指向行 \xe2\x80\x9cusing Antlr4 .Runtime.Misc;\xe2\x80\x9d(以及更多类似的内容)。
\n如果我查看菜单“工具:NuGet Package Manager:管理 Solution\xe2\x80\xa6 的 NuGetPackages”,它会清楚地显示 Antlr4.Runtime.Standard 存在并已安装(显示版本 4.8.0)。
\n我想我必须在我的项目中添加对此 dll 的引用,因此我在解决方案资源管理器中右键单击“引用:添加引用...”,但我无法在任何列表中找到它,但我进行了搜索。
\n有一个浏览按钮,我认为我可以使用它直接链接到 DLL,因此我\xe2\x80\x99 搜索了磁盘,找到了 dll 并链接到了它。现在,所有这些错误都会消失,但这可能是\xe2\x80\x99t 可能是正确的方法。
\n那么如何使用 References:Add Reference... 正确添加对它的引用?VS 知道它\xe2\x80\x99s 在那里,它显示它,但\xe2\x80\x99t 不会让它像那样被引用,因为它不会\xe2\x80\x99t 通过引用在VS 中显示它:添加引用...
\n关于您的具体问题,是的,您不想添加对 dll 的引用。相反,您需要在 csproj 中为这些依赖项添加“<PackageReference>”。所有这些都存在于 Nuget.org 中。因此,在VS2019中,右键单击解决方案管理器中的项目,然后查找“管理Nuget包”以添加Antlr4BuildTasks和Antlr4.Runtime.Standard。
Note, I've been updating the Antlrvsix extension, but haven't made a release for 2 months, longer than my usual schedule, because the next version has a huge number of changes. I will be cutting version 8 in a week. The template in VS2019 was removed because it is old and out of date. It uses an ancient version of the Antlr4BuildTasks. Instead, use the Antlr4BuildTasks.Templates v8.1 to create a C# project from scratch. Please follow the directions here. You don't need to download the Antlr tool kit, Java, or set any environmental variables. You also don't even need to use VS2019. You only need Net Core 3.1 and to install Antlr4BuildTasks.Templates. Then, type "mkdir foo; cd foo; dotnet new antlr; dotnet restore; dotnet build; dotnet run" at a command-line shell to create a C# application with Antlr4. Once you create the application, you can modify that to what you need. If you start from a Net Standard or Net Core project that doesn't have Antlr yet, you will need to add in the project reference for Antlr4.Runtime.Standard 4.8 and Antlr4BuildTasks 8.1, add in all grammars, and driver to set up and call the parser--harder to do, but it can be done through VS, or you can edit the CSPROJ file more easily and faster. The Antlr4BuildTasks looks at your CSPROJ file and will see that Antlr4.Runtime.Standard 4.8 is referenced, then will use the correct version of the Antlr JAR file to generate the parser and lexer. Any questions, let me know.
| 归档时间: |
|
| 查看次数: |
3650 次 |
| 最近记录: |