简体   繁体   中英

How can I get just the C# parser (Syntax Tree) extracted from Roslyn

I'm trying to pull in the Roslyn source code to a Unity 3D video game that will have live C# editing in it. I'm wanting the Syntax Tree, to help with debugging, formatting and analysis, and was originally planning to roll my own parser for this purpose. But if I can extract Roslyn's syntax tree to execute in Unity, that would make things a lot easier.

However, I have probably put 12 hours of time into trying to reduce the Roslyn project down (see escapades here: https://codavore.blogspot.com/2019/11/c-parser-part-2.html ) and I haven't succeeded in reducing the project. Ie removing the VB parts affect the dual test cases for C#/VB, and removing one superfluous thing affects a dozen others.

Anyone have advice for extracting out jut the C# Syntax Tree's source code?

I was originally hoping to pull in source code, but per @Jonathon Marolf's comments, I attempted to pull it in via nuget. But Unity overwrites most of what nuget does, anytime I change the files, so that didn't work. To get around this, I found and installed NuGet for Unity . Then ran the nuget "Install-Package Microsoft.CodeAnalysis.CSharp -Version 3.3.1".

Of course this broke the project, because its designed for VS projects, not Unity. I had to delete the duplicate DLLs, and also all the language support files. It still had an error with a couple analysis dlls that were unloaded when trying to run, but it was able to parse out part of the source code I passed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM