Skip to content

Unity3D and .NET Framework

Nick Jensen edited this page May 3, 2020 · 1 revision

Project files

Unity3D uses the .NET Framework, not .NET Core (dotnet) for its engines. It has its own internal way of building projects and only generates .csproj files on demand. Without the .csproj file, Unity code cannot be understood by OmniSharp-roslyn, the language server used by OmniSharp-vim and VSCode.

Unity only automatically generates .csproj files when configured to use an editor it knows. For example VSCode. If the name of your editor is not whitelisted, the files do not get generated.

You can force the generation of those files like this in Unity 2019.3:

  1. Go to Preferences -> External Tools
  2. Set "External Script Editor" to "Open by file extension"
  3. Check "Generate all .csproj files"
  4. Close unity
  5. Run the following command in your project folder to force the generation of the project files, even if you don't have VS Code installed:
    /opt/Unity/Editor/Unity -batchmode -nographics -logFile - -executeMethod UnityEditor.SyncVS.SyncSolution -projectPath . -quit
    (You may need to adjust the path to /opt/Unity/Editor/Unity depending on your installation)
  6. Now the project files should be generated

MSBuild location

roslyn/OmniSharp-roslyn may not find the correct msbuild location necessary for running .NET Framework projects. The msbuild shipped with OmniSharp-roslyn (as part of its local mono) does not contain all reference assemblies. The recommendation is to install the latest version of mono for your system, and then set environment variable FrameworkPathOverride to point to it:

export FrameworkPathOverride=/lib/mono/4.7.2-api

Alternatively, set the variable only for your vim session:

FrameworkPathOverride=/lib/mono/4.7.2-api vim Program.cs