Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Cannot add new reference to script

Discussion in 'Scripting' started by UnityNewbie9876, Nov 19, 2020.

  1. UnityNewbie9876

    UnityNewbie9876

    Joined:
    Nov 19, 2020
    Posts:
    2
    Hi everyone,

    I have a problem opening scripts from Unity in Visual Studio. I have Unity 2017.4.9f1 and Visual Studio 2017. In Unity I have integrated various C # scripts. I'm trying to open one of them as shown below.
    Unity.PNG

    When I open a script, the Explorer looks like below:
    Explorer_PC1a.PNG

    When I try to add a reference, it is not possible:
    Explorer_PC1b.PNG

    If I open the C # script from another PC, I can add the reference. The Explorer looks like this:
    Explorer_PC2c.PNG

    I have connected both PCs to a NAS and opened the exact same project. The problem cannot have arisen from copying the project. Does anyone have any idea why the two scripts behave differently? Why is the project called "Flexible_Montage_Soma" on one PC and "Assembly-CSharp" on the other PC, although I open exactly the same project? Why can I add references on one PC and not on the other?

    Thanks in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,779
    This may help you with intellisense and Visual Studio problems:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874

    Remember, Visual Studios is irrelevant to Unity. You can actually edit all your files in notepad or any other text editor. What the solution or project says is irrelevant. Unity is the actual compiler used.
     
  3. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @UnityNewbie9876

    Sorry for the confusion! That is expected behavior. The solution and projects are dynamically generated by Unity, so adding references in the Solution Explorer would not work - so it's hidden in Visual Studio when you open scripts from Unity.

    The Unity docs discuss how you can use DLLs in your projects: Unity - Manual: Managed plug-ins (unity3d.com)

    The basics are that you add the DLL to your Assets folder and use Unity to configure it.
     
    Havyx and Joe-Censored like this.
  4. UnityNewbie9876

    UnityNewbie9876

    Joined:
    Nov 19, 2020
    Posts:
    2
    Thanks for the answers.

    @Kurt-Dekker I can't follow the instructions for your first link. Probably that's because I have Unity 2017 and not Unity 2020. I can't do the following:
    Step 4:
    Make sure Generate all csproj files is checked, and Editor Attaching is checked


    My window looks like this and I don't have a choice for "Generate all csproj files":
    Edit_Preferences.PNG

    Regarding your second suggestion: Under the menu item "window" I don't have a sub-item "Package Manager":
    Package_Manager.PNG
    What can be the problem there?


    @John_MSFT As described in my question, I have the same project open on two different computers. I can add references on one computer and not on the other. My files are not integrated as DLLs, but as scripts. I'm using the same Unity version. Could it be that this is due to any settings?


    How can I alternatively attach new references to my script in Unity if this does not work by opening the script in VS2017?
     
  5. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @UnityNewbie9876

    I'm confused on which versions you're using for Unity and VS on each computer - they don't look the same.

    You should not be able to add references in the Solution Explorer using Visual Studio in newer versions of VS. The correct way is to follow the Unity documentation and put DLLs directly in your Assets folder.

    If you're not using DLLs, than I am also confused why you want to "Add References". What are you trying to do?