Visual Studio doesn't reload project after scripts are added within Unity

Hi all,

This one has me going around in circles so any help would be really appreciated.

Up until recently, perhaps within the last week, I could create a new C# script within Unity and, with Visual Studio already open, the new script would appear within the solution/project within Visual Studio.

At this current time, this is not the case. If I create a new C# script in Unity, it doesn’t appear within the opened solution/project within Visual Studio. If I double-click on the script within Unity it will open the file within Visual Studio, but because it is not deemed as part of the project, it has no references and thus no intelli-sense.

I noticed this initially using 20182.14f1, although having uninstalled that, and Visual Studio separately, re-installed both, I note that the same behaviour is now also occurring in a 2018.3.0b8 install I have also. These are the only installs I currently have but my believe would be that it would affect all installations.

If I change the view within Visual Studio you can see the file in the folder script, if you right-click on it it has the option to Include in Project. This isn’t a solution however as the file already is part of the project, proven by opening the project file and you can see the file listed.

So, the file is created correctly. Unity is updating the project file, but the project file isn’t getting reloaded within Unity.

This led me to wonder about the installed Unity Tools for Visual Studio, I have tried uninstalling these, it requires Visual Studio to be closed, upon re-opening Visual Studio they appear again, by all accounts getting automatically reinstalled.

Has anyone else come across this? I do see frequent yellow flag notification within Visual Studio when there are updates available, I normally apply these and will have done so within this time frame. I have no knowledge of which version I was running when things were ok, and when they stopped being ok.

Thanks in advance for any help.

Kind regards

Rob

Using the Get Tools and Features option from within Visual Studio I modified the installation to not include the Game Development with Unity workload.

I subsequently installed just the Visual Studio 2017 tools for Unity component.

The expected behaviour has almost returned, if I create a script within Unity, the project within Visual Studio becomes aware of it, but now, equally as annoyingly, there is a pop-up with a series of buttons requesting a decision because the project has been changed. I do not recall this being part of the behaviour I experienced previously when things were working correctly.

After changing both of these settings;

but then reverting them back to what they were originally (as displayed), I find myself having gone full circle. Visual Studio no longer updates after the project file is changed by Unity.

Any ideas? :hushed:

Are you using the standard community edition of VS that ships with unity? Or do you have a different one that you got yourself?

1 Like

Hi,

Thanks for the reply.

Just using the standard one that ships with Unity. It was installed many versions (of Unity) ago, so to be thorough, I uninstalled both Unity and Visual Studio and then when I re-installed (2018.2.14f1) there was an option for Visual Studio 2017 Community which I didn’t typically see before (because it was already installed).

So, yes, just the version that ships with Unity.

Can you just confirm something for me, just to ensure I am not imagining things… the created script within Unity should update the project file, which should then be reloaded within Visual Studio - BUT - do you typically see any prompts from within Visual Studio to advise that the project has been changed outside of the environment? I just want to be certain I am not imagining the behaviour I believe to be true. I believe this was seamless, e.g. script added in Unity, project updated, Visual Studio updated but without prompts?

That is actually not something I usually pay attention to :stuck_out_tongue:

Give me a few minutes and I’ll test it though - and let you know.

EDIT: Sometimes I do get prompts that say the solutions changed, asking to reload it - but for some reason that doesn’t always happen. Anyway I opened a new CS script, and VS does nothing. I opened the solution view, and the script I created doesn’t show up. Then I open the newly created script, and it opens like you said - as just a file. This stuff never got in my way before though - so other than having to go actually double click the file, it should all work fine.

1 Like

Same here which is why I have wondered if I was imagining it! Thanks for taking the time to have a look for me, appreciated. :slight_smile:

I edited my response with what happened, but yeah basically what you described happens.

1 Like

I also do encounter the same issue: new scripts do not get loaded automatically into VS.

Two workarounds:
a) delete the solution file so that it gets recreated from scratch
b) manually add the new scripts via project → add existing item

Far from optimal though…

Specs:
Unity 2018.2.13f1
VS Tool for Unity 3.7.0.1 (installed manually, not through Unity installer)
VS 2017 Community v15.7.6 (installed manually, not through Unity installer)

2 Likes

Thanks for checking and, in part, I am glad it isn’t only me. But, I am fairly certain this wasn’t the behaviour I was experiencing recently.

The problem with only the file opening is that you lose the intellisense, which can be a bit of a pain.

Thanks for responding and I will give the deletion of the solution a go, although it would have been created by Unity initially.

The latter option of adding the scripts within Visual Studio will work for me also, as you say, not optimal as it’s like choosing which place you will be spending most of your time. Be nice if it worked smoothly in both directions and I’m almost certain is was until recently.

Thanks again :slight_smile:

Ok this is something I’ve had happen sometimes in the past - but haven’t had this issue lately, so that makes me think that there might be some kind of glitch related to the unity > VS connection that depends on how your project is setup. Unfortunately besides that vague theory I have no idea what to try that might fix the problem :X

1 Like

I definitely think something has changed, either with updates to Visual Studio Tools for Unity, or with an update to Visual Studio, both of which are more likely to have been updated on my laptop more recently than a specific version of Unity.

It is rather odd and frustrating. Clicking on Refresh at the project level in Solution Exporer doesn’t seem to make any difference either, which is quite odd, being that I can open the project file with a text editor separately and see the new files listed.

I decided to report this as an issue on the Visual Studio support site, I ran a search first but didn’t spot anything obvious.

My issue is here:

I subsequently did find someone else who was reporting an issue (17 November 2018) with 2018.2 and experiencing the same problem, the Visual Studio team responded suggesting to check the Automatic Project Reloading setting within Visual Studio Tools for Unity but then subsequently posted to state that they had reproduced the issue. Details here:

They have created a single topic for the issue here:

It states that the issue is with VSTU, and that it has been fixed and is waiting for release!

I hope we get to see this release very shortly! :slight_smile:

2 Likes

Good work! Glad to hear its something they can fix on the VS side.

1 Like

I click RMB on project in “project viewer” and select “Set autoload project”. It solve problem for me.

Seems to be fixed in recently released update 15.9.3 for VS 2017 (Community).

Cheers

1 Like

Yep, dropped a couple of days ago I think. :slight_smile: