Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Namespace TMPro not found in Test Runner test

Discussion in 'Unity UI & TextMesh Pro' started by bluefix, Jul 19, 2018.

  1. bluefix

    bluefix

    Joined:
    Feb 24, 2018
    Posts:
    4
    When using Test Runner for a project containing TextMeshPro field, there is an error in Unity: error CS0246: The type or namespace name `TMPro' could not be found. Are you missing an assembly reference?

    Steps to reproduce:
    1. Create a new project.
    2. Add a TextMeshPro field to SampleScene
    3. Create a PlayMode test in Test Runner window
    4. In Visual Studio, in the test file, add "using TMPro;" statement
    5. It's underlined red.
    6. In Solution Explorer, in the test project, add a reference to Unity.TextMeshPro
    7. It's still underlined red.
    Is there a way to get rid of that error? I have it in 2018.1 and in 2018.2
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,849
    I am assuming that you have installed the latest TMP UPM package (version 1.2.4) via the Package Manager UI and subsequently imported the TMP Essential Resources?

    (1) I just created a new project in Unity 2018.2.
    (2) Made sure the TMP UPM package we already installed which it is for Unity 2018.2.
    (3) Imported the TMP Essential Resources.
    (4) Created a test folder.
    (5) Open the Test Runner and use Create Test Script in current folder (the one I created above)
    (6) Adding the using TMPro;

    The steps above worked as expected on my end.

    Make sure that you are using the latest version of Visual Studio 2017 which is 15.7.5. If not, see if you get the same behavior with this latest release. If you are doing this in the same (new project), make sure you delete any solution created in that project and the Library folder.

    Let me know what happens.
     
  3. bluefix

    bluefix

    Joined:
    Feb 24, 2018
    Posts:
    4
    I have now Unity Personal 2018.2.0f2, VisualStudio Community 15.7.5 and TextMeshPro 1.2.4
    After updating VS to this version, nothing changed, there is the same error.

    (1) I created a brand new project in 2018.2.0f2 (those previous I mentioned before were imported from 2018.1).
    (2) TMPro was already installed in Package Manager.
    (3) I clicked "Import TMP essentials" before adding a TMPro field
    (4) Selected the root (Assets), opened Test Runner and clicked on "Create PlayMode test assembly folder" (with name MyTests2)
    (5) Then I created the script and opened it in VS.
    (6) Tried to add "using TMPro", intellisense doesn't suggest TMPro, after typing manually it's underlined in red.

    I don't know if it matters, but if I click in VS on "MyTests2/References" there is no Unity.TextMeshPro reference. However, in Assembly-CSharp/References there is such reference.
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,849
    The step that I missed which is causing the issue is related to the use of an Assembly Definition in this created test folder.

    The solution is to manually edit the .asmdef to add a reference to the Unity.TextMeshPro assembly.

    In order to do so, select the file and use the context menu "Show in Explorer" and then open the file in some text editor to make the following changes..

    Code (csharp):
    1.  
    2. {
    3.     "name": "Tests",
    4.     "references": [ "Unity.TextMeshPro" ],
    5.     "optionalUnityReferences": [ "TestAssemblies" ]
    6. }
    7.  
     
  5. bluefix

    bluefix

    Joined:
    Feb 24, 2018
    Posts:
    4
    This is working now, thanks!
     
    Stephan_B likes this.
  6. SusterDrifter

    SusterDrifter

    Joined:
    Jun 12, 2018
    Posts:
    3
    I am sorry, where do I find the .asmdef file ?
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,849
    When the Test Runner creates the folder, it adds the .asmdef file in that folder.
     
  8. Xavier78

    Xavier78

    Joined:
    Oct 13, 2013
    Posts:
    5
    So better fix then having to edit the file for each script. It looks like you need to update Visual studio, because it is trying to build the references for the project, but is looking for them in the old location(aka not the new "Packages" folder in your project folder, but in your user folder?). Once updated It should rebuild for the project, if not maybe hit rebuild, or take out the "Unity.TextMeshPro.csproj" and "Unity.TextMeshPro.Editor.csproj" files from the project folder. Hope this helped someone else.
     
    Last edited: Oct 10, 2018