'Visual Studio (Mac) does not recognize some Unity types

I am creating a class library which needs to reference Unity-specific types like GameObject for example.

  • I am on MacOS (latest)
  • I am using Visual Studio Enterprise 2019 for Mac [Version 8.6.2 (build 6)]
  • I am using Unity 2019.3.14f1

My setting

In my C# project I am setting the same target .NET as the autogenerated C# project in one of my Unity projects:

<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

Then, as instructed in the documentation on plugins, I am referencing the DLLs:

<ItemGroup>
    <Reference Include="UnityEngineRoot">
        <HintPath>$(UnityBasePath)UnityEngine.dll</HintPath>
    </Reference>
    <Reference Include="UnityEngine">
        <HintPath>$(UnityBasePath)UnityEngine/UnityEngine.dll</HintPath>
    </Reference>
    <Reference Include="UnityEngineCoreModule">
        <HintPath>$(UnityBasePath)UnityEngine/UnityEngine.CoreModule.dll</HintPath>
    </Reference>
    <Reference Include="UnityEngineAnimationModule">
        <HintPath>$(UnityBasePath)UnityEngine/UnityEngine.AnimationModule.dll</HintPath>
    </Reference>
    <Reference Include="UnityEditor">
        <HintPath>$(UnityBasePath)UnityEditor.dll</HintPath>
    </Reference>
</ItemGroup>

Where UnityBasePath is: /Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/Managed/.

The problem

Everything actually compiles just fine!

using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;

public class MyClass
{
    private UnityEngine.GameObject obj;
    private AnimationClip clip;
}

The class above compiles just fine.

Problem is Visual Studio IntelliSense which underlines in red most of the types I am using (making the dev experience quite painful):

The type name 'Object' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.

But as you can see from the code I posted, I have referenced UnityEngine.CoreModule! I also get this for AnimationClip:

The type name 'AnimationClip' could not be found in the namespace 'UnityEngine'. This type has been forwarded to assembly 'UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.

And there as well, module UnityEngine.AnimationModule has been referenced.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source