tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4
Other
450 stars 103 forks source link

VS 2012, trying to install from Nuget, "External packages cannot depend on packages that target projects" #198

Open achedges opened 7 years ago

achedges commented 7 years ago

I've found the pre-release "ANTLR 4" package, id 'Antlr4', but I'm receiving this error when trying to install, after selecting the VS project (which is brand-new). I'm not familiar enough with Nuget to know how to look for a solution.

Also, I'm not opposed to using the standard ANTLR jar to output C# files, but there are a handful of errors that have to be manually fixed when doing that (incorrect capitalization, references to non-existent methods, etc). The grammar I'm working with is 3rd party and subject to change, so I'd like to be able to re-generate as needed without having to keep fixing the same issues.

So, is there an 'officially blessed' command line version of the ANTLR tool that will generate C# code properly, without going through Visual Studio?

lextm commented 7 years ago

When you are not familiar with the necessary bits, use the stable version instead of pre-release version first.

achedges commented 7 years ago

Fair enough, but Step 4 in the read-me says "...change selection to Include Prerelease". I assumed it said this for a reason.

lextm commented 7 years ago

The Readme file is more developer oriented I think. You can read "Pre-release Builds" section,

To ensure the highest level of reliability for developers targeting final releases of particular versions of the ANTLR 4 Runtime, pre-release builds use a different strong name key than final builds.

Besides, it is very strange that you met "a handful of errors". You should show them with details instead of asking others to guess.

achedges commented 7 years ago

The 'handful of errors' are simple code issues in the generated lexer/parser (for example, referencing a method name with the wrong capitalization). These code files were generated using "java -jar antlr-4.6-complete.jar -Dlanguage=CSharp mygrammar.g4". I had already worked around these issues by modifying the generated code, and had produced a working project as a proof of concept.

Now I need to make this project more official and accessible to my team, and I thought perhaps these code issues were caused by me using the wrong tools to generate the code. I thought the antlr4cs project might do everything correctly. So that brings me here, and following the read-me leaves me with the Nuget error in the title. So that's my question...why is Nuget throwing this error? I'm not asking about the 'handful of errors' per se, I'm trying to install the Nuget package. If that ever works and I still see these errors, then I'll post the details.

Maybe I'm misunderstanding the purpose of the Nuget package. If the "proper" method of generating C# code with ANTLR is to use the jar as stated above, then I need to post a new issue about the compile errors in the generated code. If there's a different tool that's tailored specifically for C# (which is what I thought this package was), then I assume I should use that.

sharwell commented 7 years ago

This appears to be a limitation in older versions of NuGet, which would be difficult to work around while continuing to properly support newer versions. You may need to install these packages using a newer version of Visual Studio, after which point Visual Studio 2012 will still be able to restore these packages during a build.

heck4 commented 6 years ago

There is a workaround to fix the NuGet package, so it works on older Visual Studio versions.

https://danlimerick.wordpress.com/2011/10/01/getting-around-nugets-external-package-dependency-problem/

Basically the package needs to have either a lib or content folder, with a file in it. In the article above, he adds a InstallationDummyFile.txt, and then deletes it from the project and folder using the install script:

param($installPath, $toolsPath, $package, $project)

$project.ProjectItems | ForEach { if ($_.Name -eq "InstallationDummyFile.txt") { $_.Remove() } }
$projectPath = Split-Path $project.FullName -Parent
Join-Path $projectPath "InstallationDummyFile.txt" | Remove-Item
sharwell commented 6 years ago

@heck4 thanks for the links