Cannot add new reference to script

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.
6539962--739309--Unity.PNG

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

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

If I open the C # script from another PC, I can add the reference. The Explorer looks like this:
6539962--739363--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.

This may help you with intellisense and Visual Studio problems:

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

Also, this: No suggestions in Vscode

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.

1 Like

@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.

2 Likes

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”:
6561949--743431--Edit_Preferences.PNG

Regarding your second suggestion: Under the menu item “window” I don’t have a sub-item “Package Manager”:


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?

@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?