- Home /
[2018.4] Using Roslyn Code Analyser
Long story short, I'd like to use the Roslyn Code Analyser to compile C# code at runtime. I'm wondering if that's possible with the advent of C# 7 being included in Unity. I've tried to NuGet the Roslyn stuff into my Visual Studio project and copy the .dlls into my Assets folder, but Unity complains about dependencies. Visual Studio does not.
So I solve those dependencies. And more dependencies pop up, and I solve those, and so on and so on until I get bored. Must have gone on for an hour or more. Got to ludicrous stuff like SQLitePCLRaw stuff. I think it was just trying to include literally everything available in the C# language.
I'd rather not use the Asset Store solutions, as I'd like to learn how to do it myself.
Answer by Nosrick · May 13, 2019 at 03:36 PM
So I'm going to answer my own question.
You've just gotta keep on including those ridiculous dependencies until the compiler gets tired and goes to sleep. Then it works! I've got Roslyn scripting in my game working perfectly.
I have tried this approach with Unity 2021.2 and 2022, but I always seem to hit a dead end. Any pointers?
I don't know if the new Unity supports it, but if your IDE can use NuGet, try that. It'll grab all the dependencies for you.
My solution in the end was switching to Godot.