Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug Visual Studio integration is pretty busted

Discussion in '2020.2 Beta' started by Hertzole, May 9, 2020.

  1. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    Hello

    I've been working with the alpha for some time now and pretty much through the entirety of that time, Visual Studio and Unity has not been working nice together at all. Am I the only one with these problems? I would've thought someone else would've posted it by now, but I guess not.

    To start, clicking ANY Debug.Log message fails 99% of the time. If I get an error in the console I can't click on it because it will open up in my default text editor instead and Visual Studio will be prompted to reload the project several times.

    Creating a new script in Unity prompts VS to reload again, but even after reloading it feels like a 50/50 chance it will open in VS or the default text editor if I click on it inside Unity. So I have to create the script then go to Visual Studio and fish it out of my project browser.
    Creating a script inside Visual Studio though breaks it even more. I can create a script, edit it, and all that, but as soon as I go into Unity and it does it's thing, Visual Studio seemingly loses all references. All my connected assembly definitions are lost and I have to restart Visual Studio to get it back.

    Lastly, a problem that I don't know if it's directly related to Unity + VS but I thought I should just mentioned it anyway. The Visual Studio integration package is one massive thorn in my side. Since I've been encountering other bugs I've been deleting the Library folder quite often. In there, in the package cache, that package has a "vswhere.exe" file that is ALWAYS locked somehow. I can't delete it normally and has to resort to programs like Unlocker sometimes, BUT EVEN THAT can fail. This also stops me from reporting bugs because the bug reporter also has a problem with it. I have to restart my PC every time I do it which I'm not quite fond of.

    I don't know if it has something to do with me using a preview version of Visual Studio 2019 but it works fine in older Unity versions like 2019.3 and 2020.1. I find it odd that no one else has mentioned this... I can't be the only one, right?

    I also don't know quite how to report bugs like this and therefore I haven't reported any of it.

    small rant over
     
    KCAR, ROBYER1, elZach and 1 other person like this.
  2. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    I have the exact same problems, but I'm using 2021.1 beta. I think it started around beta 4 once I upgraded to the latest package of VS.
    One thing I found to help it a little bit is to go to editor preferences -> external tools and force Unity to use a specific version of VS. It doesn't solve it completely but it does synchronize more like that
     
    Hertzole likes this.
  3. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    No, I'm experiencing all of those problems, too.
     
    Hertzole likes this.
  4. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I do like the new change on Unity VS package 2.0.1 where you can choose which projects to include on the solution, this has never worked properly before for me but now it's pretty robust.

    What fails for me every second time though is when I double click the error on console or file in the editor, it often only loads individual file in VS instead of the whole solution. I then have to close VS and try it again and it opens it properly on the second time. On the first time when it fails, it doesn't have any refs without the solution so editing the file it pretty busted as there's no functional intellisense (until I reload the file again and it opens it along with the solution).
     
  5. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    Same issues here. Randomly Unity wants to open scripts in VS 2013 despite VS 2019 being set in preferences and having an instance of it open and ready. I have to click the Regenerate Project Files button all the time and honestly just stopped creating and opening scripts from within Unity, too much of a headache.

    Looking forward to a fix.
     
    Last edited: May 18, 2020
  6. elJoel

    elJoel

    Joined:
    Sep 7, 2016
    Posts:
    125
    Same problem here
     
  7. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    For what it’s worth, scripts seem to correctly open the solution in Rider.
     
    Crayz likes this.
  8. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    I thought it was just me. I uninstalled VS 2019 and went back to 2017 because of this but that didn't really fix it. I have to regenerate files every time when I open Unity, but even then things end up breaking randomly after a while.
     
  9. Eric-van-Gastel

    Eric-van-Gastel

    Joined:
    Jan 2, 2016
    Posts:
    21
    I have a likewise issue. When I open a script by double clicking it within the Unity project view, it opens the script without opening the C# project. Any reference to another class is broken. I can't do anything like this.

    The weird thing is that I've been using Unity 2020.2 just fine last week. It just randomly, suddenly, and for no apparant reason broke this morning.
     
    Ruslank100 likes this.
  10. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    Hey @RealMTG and all, Program Manager of Tools for Unity here.

    The best way to report issues with Visual Studio so we can fix them quickly is to use the Help > Report a Problem menu from within Visual Studio. From there, you can document the issue and your version information and logs are included automatically. That helps us diagnose.

    Would you mind filing a report that way and include as much detail as you can? For example, when you click Debug.Log and it fails, what do you mean by fail?

    For everyone else having these issues (or other issues) please report the same way, or add a comment to an existing post that is similar. If you'd prefer to work 1:1, message me on here or on Twitter (@jmillerdev).
     
    cultureulterior likes this.
  11. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    I'll report my issues as soon as I can! Should I report them all individually or combine most of them?
     
  12. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    It's best to report 1 per issue, but I understand that can be a major pain. Whatever you can provide will be a great first step!
     
  13. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    A great first step if you're having the issues mentioned in here is to make sure you're using the 2.0.2 version of the Visual Studio package. If you do update to that, and it resolves or not, please let me know!
     
  14. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    2.0.1 is the latest version in package manager for me.
     
  15. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    I'm going to start collecting some videos on the issues because I believe they may be hard to reproduce if you're unlucky. But I won't report anything until I've tested that new version (which hasn't shown up yet, as Crayz pointed out).
     
  16. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    Doh, sorry about that... It's live now.
     
    Crayz likes this.
  17. elJoel

    elJoel

    Joined:
    Sep 7, 2016
    Posts:
    125
    In Edit --> Preferences --> External Tools

    upload_2020-6-2_23-28-7.png

    Setting the External Script Editor to Visual Studio and Regenerate project files. Solved the problems for me.
     
  18. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    @John_MSFT Why did you make the decision that these fields should be a global configuration and not by project? Maybe in a certain project I want to have more packages in the solution to be able to debug certain code better but not in other projects.
     
  19. visose

    visose

    Joined:
    Nov 2, 2014
    Posts:
    28
    Version 2.0.2 still does not support C# 8. This is a very simple fix, strange it didn't make it on this update.
     
  20. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    2.0.2 seems to have fixed the issue of opening the wrong editor. Only issue I've noticed is clicking a script shortly after renaming/deleting/creating another script before assets have had a chance to refresh will open a new instance of Visual Studio.
     
  21. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    A lot of my issues seem to have been fixed with the release of 2.0.2 but some persist, like this issue I just found:
    Having a simple Debug.Log that is called from a rather lengthy stack trace (like in my case LevelController, LevelSaver, ObjectManager, Object, MyTroubledClass) and then clicking on the message in the console will go to the first item in the stack trace. I would expect it to go to the class with the Debug.Log message.
    Maybe something of interest to you, @John_MSFT
     
  22. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    I have the same issue. It should definitely open the last item. Anything else doesn't make sense.
     
  23. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Man, I gave up on Visual Studio ever actually working about ~4 years ago. Apparently that was the right choice!
     
  24. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Integration has mainly been bust since they moved it into package around 2019.2 or so. After that everything that just worked.. now work every second time at best :p For example clicking on the console for the error was finally robust before this move, it just opened the right place on VS. Now it's pretty hit and miss.

    I'd love to see this to get more love as I really prefer VS as my IDE. But it does tell a lot that even Unity staff is using Rider instead...
     
  25. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @RealMTG

    Thanks for letting me know. For any issues you have with VS, please log them via the Help > Report a Problem menu inside Visual Studio.

    @Baste I'd love to learn more about why you gave up! If you're willing to share your experience, please send me a message.

    @rz_0lento What other issues have you had? For any bugs you're experiencing, with VS or the VS Package in Unity, please report via Help > Report a Problem.
     
  26. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    @John_MSFT, overal poor performance, both with regards to startup and use, a small and low quality refactoring set, poor update workflow, the Unity integration moved very slowly, the Unity integration had frequent regressions, the IDE itself had frequent regressions. Bug reports didn't get timely replies and I couldn't find anywhere to follow their resolution.

    Jetbrains Rider essentially beats you on every single metric that I could care about, including price if we don't qualify for Community Edition. I gave it a spin for a one month trial, and I couldn't come up with a single reason not to change over.
     
    John_MSFT likes this.
  27. airnamics

    airnamics

    Joined:
    Feb 5, 2020
    Posts:
    28
    Yes, same, I and my coworker tried 2020.2.0a13 and we got furious with VS. Scripts do not regenerate, debugging functionalities is non-existant, sometimes VS opens twice and so on.
     
  28. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    My two main annoyances that make using VS pain with Unity are:

    - double clicking a file from unity's project tab or error message from console doesn't open the whole solution in VS, instead more often it just opens single file in new VS instance (sometimes even when the solution is open in other instance of VS.

    - VS solution gets constantly redone for whatever reasons and VS prompts if I want to reload or ignore this. This usually just freezes VS fully for like 10-30 seconds (I'm on a really high end rig here with fast nvme etc). This totally shouldn't happen. What I usually just do now when I see this dialog is that I just open task manager and force kill VS as it's simply the fastest way to get this thing responding again.

    All in all, I'm a long time fan of VS but current experience with Unity is just horrible. It's not just on Unity 2020 but also on 2019.3/2019.4. Basically the issues started the moment VS integration from Unity moved into package, it worked pretty fine right before that.

    In addition, debugger attaching has become less robust, I fight this more than ever before.
     
    Alic and rmb303 like this.
  29. Per-Morten

    Per-Morten

    Joined:
    Aug 23, 2019
    Posts:
    119
    Particularly agree on that last point. Lately, I've had lots of issues attaching the debugger in a timely manner. Usually, it ends up with me trying to attach the debugger, Unity goes busy for a while (I usually assume that Unity is frozen after about 30 seconds, then restart both the Unity editor and VS), then *maybe* I get to debug.
    Other times I seemingly manage to attach VS to Unity, but breakpoints are never triggered. Sometimes I need to delete all breakpoints before I can manage to attach VS to Unity. Sometimes I attach VS to Unity, but then I can't interact with Unity anymore (Unity is frozen, I can't hit play).

    Attaching and debugging with VS worked 98-100% of the time for me before. Lately, it's been an exercise in restarting both the editor and VS to see if that fixes the issues. This is particularly frustrating when you need to debug something that has long load times.
    It's a shame, because VS is by far my favorite IDE, and I've been very happy with many of the new features. Getting package source code in VS, for instance, has been a game-changer for playing around with DOTS.
     
  30. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    I can't even use debugging at all with Visual Studio, I don't know if its a problem with Unity or VS, I just get loads of random errors.
     
    stonstad and ROBYER1 like this.
  31. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    Thanks, everyone! This feedback is helpful.

    The first steps are to make sure you are updated to the latest VS Package from the Unity Package Manager. If you can, also update to VS 2019, or update your existing 2019 installation.

    Running the latest versions of the VS tools doesn't require you to update Unity, so you're project will remain compatible with whichever version you're using.

    If you're running the latest, or can't update, please file a bug via Help > Report a Problem (menu in Visual Studio). Include details like the version of Unity you're using. the platform you're debugging (Android, Windows, etc.) and any other information (screenshots, details, steps you're taking, a project that we can use to reproduce the issue, etc.).

    I'm also available to troubleshoot directly with you - simply send me a message on here and I'll get back to you.
     
  32. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Visual Studio 2019 has build error with Rewired Plugin,

    https://developercommunity.visualst...-studio-2019-miscompile-in-release-build.html

    I recently tried it with Visual Studio 2017 15.9.24 and has the same problems there too.

    When I used VS 2019, I could not get my debugger to keep attached to Unity, as it stops debugging as soon as I return to Unity. At least 2017 it works there. Sometimes more than one instance of the VS opens when I click console debug log.
     
  33. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @castor76

    It looks like the Rewired issue is a bug filed with the C++ compiler team already.

    The debugger / VS opening issue sound related to a known issue in the Visual Studio Package. Are you using Unity 2020.x? If so, please use the Unity Package Manager and update the Visual Studio Package to version 2.0.2.
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I am using 2020.2 alpha and using package version 2.0.2

    And this rewired issue was reported long time ago, any new development from them? It seems to take just too long for this to be fixed.
     
  35. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    Feel like this needs to be brought up again. Still happening for me, and you have to wait a good 20 seconds or so between creating a script in Unity and opening that script otherwise Unity will just launch up a new instance of Visual Studio. Quite frustrating..
     
    rz_0lento and ImpossibleRobert like this.
  36. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    232
    VSnotworking.png Yeah I don't know what is going on now, suddenly Visual Studio has stopped recognising all the Entities, InputSystem, Mathematics, Physics, Transform namespaces. I've tried rebuilding it and reloading but nothing seems to work, its unusable.
     
  37. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    Happens a lot.

    Popular is also selecting a random assembly. You can't code in your main assembly, unless you select it again manually.
     
  38. TheZombieKiller

    TheZombieKiller

    Joined:
    Feb 8, 2013
    Posts:
    266
    @John_MSFT Is there any news on the removal or tweaking of the following change?:

    Unity 2020.x has supported C# 8 for a while now, but due to this still being present, VS reports errors when using C# 8 features. Currently the only solutions I'm aware of are to either downgrade the VS integration package (not ideal), store a modified version in your project's packages directory (not ideal), or use a script to forcefully set the LangVersion property on all generated .csproj files to 'latest' or 8 (also not ideal).
     
    ImpossibleRobert likes this.
  39. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @TheZombieKiller

    We have a solution ready for the next release of the package - working on the details of the date now.
     
    rz_0lento, TheZombieKiller and rmb303 like this.
  40. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    still same problem. vs2019 newest, unity 2020.1.9f1, unity can't open script file. I did everything on the internet.
     
  41. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Also experiencing similar problems on 2020.1 and 2020.2 releases. Some of the problems include: VisualStudio not opening scripts (even after attempting workarounds described here), Unity opening multiple instances of VisualStudio, making VisualStudio crash when creating new scripts and shaders, constant requests to reload project's C# solution, etc.
     
  42. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    For anyone experiencing issues with Visual Studio like mentioned above, please send me a message here if you're willing to work directly with me to resolve it.

    These issues shouldn't be happening and I'd love to troubleshoot them quickly and get it working for you while discovering the root cause so we can fix it. Thanks!
     
    LeonhardP and ImpossibleRobert like this.
  43. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    I'd love to help out and debug. But got work todo.
    For what its worth though, I get these on the daily:

    1. Visual Studio opens multiple instances. Old instances sit there with a "Reload Solution" popup. Usually by the end of the day, I have 10 VS instances open.

    2. Switching to a script inside another assembly within Visual studio: Sometimes VS won't save the file. I've lost work because of this. You make changes, hit save, don't notice Unity didn't re-compile, close VS, and suddenly all that work is gone.

    3. VS won't open the file I double clicked on. Have to switch back to Unity, and double click again. This sometimes opens a new instance as well.

    4. Clicking inside the Unity console on a script error also opens new VS instances.

    The new instances problem seems to be a mix of creating new scripts in new assemblies (asmdefs), creating new assemblies, switching to scripts in different assemblies then returning to Unity and double clicking a script to open.
     
  44. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    I want to.
     
  45. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    530
    I have actually pulled the line and switched to Rider because of the many issues that are suddenly in the VS package which I never had for years. It would simply not show me my editor folders anymore for some reason. It got to the point where my productivity would be in danger so I bit the bullet and shelled out the Rider license. I still like some aspects of VS better like the much faster usages resolution or jump to definition but the whole thing needs to work reliably again. Will check again in a year when my license expires :)
     
  46. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Is rider have full functions VS has? Is it replaceable VS?
     
    ImpossibleRobert likes this.
  47. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Please keep the thread on topic. It's better to ask this in a dedicated thread in the Scripting forum.
     
  48. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    I don't know why this happen but,

    Original my project file exist at D: drive, have no problem to run VS inside unity script,

    now copy this whole project folder to another drive, F:, and then run unity at F: and try run script inside, but VS does not start.

    Very strange phenomenon....
     
  49. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    194
    Problem still exists where if Visual Studio has any prompt open attempting to open a script from Unity will cause a new instance of Visual Studio to open.

    This has been a pain in the ass for a very long time.

    When toying around inside Unity deleting/renaming/moving script files occasionally Visual Studio will open a prompt in the background asking to reload solution. If you don't check for this prompt before opening a script in Unity suddenly you're waiting on Visual Studio to open and load a new instance.

    2020-12-03_20-31-33.mp4 (streamable.com)

    @John_MSFT is there a fix for this?

    edit: On the bright side, this (for me) is the only remaining problem with Unity/VS.
     
  50. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I agree. However, I don't think this is a bug, but rather annoying practice that we need to work around with. I hope this gets better. Like... auto reload every time option or something.