Setting up Roslyn Parser In Unity

So, I did manage to get the Roslyn C# Parser partially running, on the last commits of the Proof development. Now I'm putting Roslyn back in.  As I'm finding the same hurdles I thought I would call them out more clearly for others to tread.
Generated on WordClouds.com, from sample C# parsed by Roslyn SyntaxTree

First off, it wasn't a straight forward install, of just add this package and go. The first step was to install NuGet for Unity, as found here: (https://github.com/GlitchEnzo/NuGetForUnity). Instructions and download are there. Keep in mind: NuGet Packages are typically designed for Visual Studio solutions, but this is Unity. Many packages will not work out of the box. Roslyn is no exception.

So now, with NuGet running, we need to pull in Roslyn. Search for "Microsoft.CodeAnalysis.CSharp" and pull it in. Once done, there will be a handful of errors, relating to references being missing or incompatible.  So now we need to fix those errors.

Now, at this point, I should say that these errors disappear when you clear the console, unlike syntax errors. To get a list of them to show up again, you need to try playing the scene.

Next, there are different "Microsoft.CodeAnalysis.Analyzers.resources.dll" files for different languages or regions. NuGet puts them all in place, and normally, Visual Studio can sort this out, but Unity is not equipped for it. To clear this, find and delete the folder, "Assets/Packages/Microsoft.CodeAnalysis.Analyzers.2.9.6/"

Now find the folder "Assets/Packages/Microsoft.CodeAnalysis.Common.3.4.0/lib/netstandard2.0/". Delete all the sub folders.  And then again for "Assets/Packages/Microsoft.CodeAnalysis.CSharp.3.4.0/lib/netstandard2.0/".

Now, if you try playing, it should not throw exceptions.

I plan to update this with a sample video or two of how it was setup, and what initial tests I put it through, along with the code for parsing a full syntax tree.



Comments

  1. Ran this again on the new setup. There are some changes, but its mostly the same. Notedly, after installing the nuget package, I must remove NuGet, since its current design keeps putting the deleted files back.

    ReplyDelete

Post a Comment

Popular posts from this blog

C# Parser and Code View

A Momentary Lapse of Passion

How to Setup a Multi-Scene Unity Project for Startup