TMPro not found in Visual Studio Code

Viewed 13778

I'm using Visual Studio Code to write my code for Unity. The following extension I've added to Visual Studio Code: C#, Debugger for Unity, Unity Code Snippets & Unity Tools

Using TMPro to work with TextMeshPro components throws me this error:

Unnecessary using directive. [Assembly-CSharp]csharp(CS8019)
The type or namespace name 'TMPro' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp, Assembly-CSharp, Assembly-CSharp, Assembly-CSharp, Assembly-CSharp, Assembly-CSharp, Assembly-CSharp]csharp(CS0246)

On the bright-side, in Unity Editor no errors are thrown, but it is still annoying.

Does anybody know if there's an additional Extension I have to download or how to fix this issue?

Best

7 Answers

I have had this for ages, here is the solution for Unity 2021.1 and latest Vscode plugin:

Go to preferences>External tools and Untick everything (all generate csproj tickboxes) delete all the sln and CSproj files.

Hit Regenerate project files.

I ran into this problem after I had set up unit tests within Unity. If you have an assembly definition file in your Unity project then it needs a new Assembly Definition Reference added in the inspector. In this case, Unity.TextMeshPro.

If you have moved your project into a different folder, be sure to update Assembly-CSharp.csproj to have the new, correct filepaths for libraries like TextMeshPro and UnityEngine.UI.

Turns out the issue was that within the *.sln file of my project the references were not found due to the lack of the path to the *.dll file.

Deleting Unity.TextMeshPro and Unity.TextMeshPro.Editor and then re-importing them solved the issue.

In my case I had to add a script assembly to my "Scripts" folder (where I keep all my scripts for a game). Once that was done I added a reference in "Assembly Definition References" and selected "Unity.TextMeshPro" then I could add using TMPro; to my script.

This didn't used to happen and I suspect it's the Test Runner complaining because it doesn't know what "TMPro" is.

unity3d assembly reference for TextMeshPro

Open the Package Manager and make sure you installed the TextMeshPro package. If this error persists, restart the Unity Editor.

In my case the answer was to delete all the project files, reinstall TMPro in the package manager, and delete all the folders at Library/PackageCache/

Related