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.
When I open a script, the Explorer looks like below:
When I try to add a reference, it is not possible:
If I open the C # script from another PC, I can add the reference. The Explorer looks like this:
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?
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.
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.
@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”:
Regarding your second suggestion: Under the menu item “window” I don’t have a sub-item “Package Manager”:
@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?
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?