Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Double clicking a C# script should open Visual Studio

Discussion in 'Editor & General Support' started by Dave-Hampson, Jun 12, 2014.

?

If you try, can you open a script in Visual Studio okay?

  1. I am using 4.5.1, 4.5.0, 4.3, 4.2, 4.0, 3.x and it doesn't work

    41.2%
  2. I am using 4.5.1, 4.5.0, 4.3, 4.2, 4.0, 3.x and it works fine

    4.4%
  3. I am using 4.5.1p1, 4.5.2 etc and it doesn't work

    22.1%
  4. I am using 4.5.1p1, 4.5.2 etc and it works fine

    7.4%
  5. I mostly use Visual Studio 2008

    2.9%
  6. I mostly use Visual Studio 2010

    7.4%
  7. I mostly use Visual Studio 2012

    8.8%
  8. I mostly use Visual Studio 2013

    39.7%
  9. I mostly use MonoDevelop

    11.8%
  10. I mostly use something else

    4.4%
Multiple votes are allowed.
  1. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150
    Hi folks,

    Unity 4.5.1p1 is out with this bugfix:
    http://issuetracker.unity3d.com/iss...ill-open-monodevelop-instead-of-visual-studio

    Like all great bugs this was not one large bug but 2 or 3 smaller ones masquerading as one big one.
    Also, like all great bugs, this did not happen on everyone's machine.
    Because of this what I would like to do is, after 4.5.1p1 is released, try and get a bunch of votes to determine whether I successfully fixed every variant of the bug. Note 4.5.1 aka 4.5.1f3 does not yet have this bugfix.
    So once p1 is released please read the options for the poll carefully and pick the answers which matches your situation best. It's multiple choice so please tick all that are relevant. For science!

    Don't forget to set VS as your External Script Editor in preferences:
    vs2008.png
    Very much appreciated folks, and hope to fix some more stuff in the future for you!

    Dave
     
    Last edited: Jun 13, 2014
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    FWIW, I see the release note for p1 says that 'If Visual Studio is open with another project' then it'll still fail. I think that in pretty much every previous situation I've encountered this bug (and yeah it's been pretty frequent), there's been a devenv.exe running in the background that I've had to kill...
     
  3. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150
    That sounds like yet another variant of the bug which I haven't reproduced or fixed yet.
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Ah, interesting. Might have something to do with Resharper being installed…

    Also, in the past it's been 100% reproducible that if Visual Studio is displaying a modal dialog, Unity fails to make it open the project and falls back to MD. Does that sound like one of the fixed cases?

    (If that doesn't sound familiar to you, try these repro steps:
    * Create a project with a script in, double-click the script to go to VS
    * In VS, add a new code file
    * Go back to Unity and double-click the new code file
    * VS displays 'discard project changes?' dialog. Don't dismiss it.
    * Go back to Unity and add a new code file, double-click it
    * Unity attempts to talk to VS, fails, opens MonoDevelop)
     
    Last edited: Jun 14, 2014
  5. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150

    Ah, good repro steps, I'll add that to the fogbug notes on Monday.

    One of the things is that if the VS launch fails for any reason, the code is designed to "run home" to MonoDevelop as a fall back instead of actually reporting the error to the user. This makes sense from a "I just want to see the script dammit" pov, but feels kind of annoying if you are trying to diagnose a problem with VS launching.

    It might make sense for me to at least add some debug logs so we can differentiate all the different failure cases, and possibly disable the MD fallback.

    Hey remember I said this bug was actually 2-3 smaller bugs? Make that 5-6 ;-)
     
  6. bpdavis2006

    bpdavis2006

    Joined:
    Jun 3, 2013
    Posts:
    19
    Out of curiosity, what is the latest version of Unity (free) that allows VS 2008 to open projects correctly? Thought I'd upgrade from 4.1.3f3 and discovered this unfortunate bug in 4.5.1. Just trying to avoid another 1+ GB download. :)
     
  7. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150

    Can you try 4.5.1p1 and see if it is fixed?
    http://forum.unity3d.com/threads/unity-patch-releases.246198/#post-1662438
     
  8. bpdavis2006

    bpdavis2006

    Joined:
    Jun 3, 2013
    Posts:
    19
    Downloaded 4.5.1p4 and VS 2008 opened fine. :D

    Thanks!

    Incidentally, I didn't realize until going to the link you provided that the "p" stood for patch. I was thinking it stood for "pro".
     
  9. Yotzee

    Yotzee

    Joined:
    Jul 14, 2014
    Posts:
    1
    Copied from other thread:http://issuetracker.unity3d.com/issues/double-clicking-a-c-number-script-will-open-monodevelop-instead-of-visual-studio
    I am still seeing this issue on 4.5.2f1 using VS2012 and Windows 8 (Surface Pro 2) - Does anyone have a fix for this. Is there a timeout on how long it takes VS to open and if it fails to open in that time then opens MonoDevelop... ?? Is there a way to change that...

    Tryed
    renaming executables.. Failed
    reinstalling and installing in different orders.. Failed
    restarting... Failed
    creating new project / new solutions... Failed
     
  10. philippen

    philippen

    Joined:
    Feb 7, 2013
    Posts:
    1
    Hello,

    I have upgraded from Unity 4.5.1 and now the problem seems to be worse with 4.5.2f1.

    All my projects now refuse to open Visual Studio 2010.

    Older versions of Unity would at some point open Visual Studio 2010 on the second try when clicking on a C# script.

    I am using Visual Studio Professional 2010.
     
  11. skuami

    skuami

    Joined:
    Jul 16, 2013
    Posts:
    5
    I'm having the same issues with Unity 4.5.2f1 and VS2013 Premium. I'm running also VS2012 Premium and have the same problems. Unity starts always VS2010 Shell with the message that I dont have a license.

    I tried to change registry keys, changed default settings for *.cs, *.sln, *.cproj files etc. Without any success.

    It only works when I start the solution manually in VS2013.
     
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    As discussed in the issue tracker for this problem, I have made some changes to improve the behavior in 4.5.3p1.

    @superpig: I believe these changes will improve the situation that you reported, although it will not be fixed entirely. In your last step (Unity attempts to talk to VS, fails, opens MonoDevelop), now a new session of Visual Studio will start instead of MonoDevelop. Unfortunately, we can't do much about the Visual Studio session that has a modal dialog. When that is the case, any communication with Visual Studio from the Unity editor will be rejected by Visual Studio, so we can't even determine if a given Visual Studio instance is the one with the Unity solution currently open. So I think our best option is simply to open a new instance of Visual Studio. This should be an improvement over the existing behavior though.

    @philippen: I wasn't able to reproduce your specific problem, but I think the additional information written to the editor log in 4.5.3p1 will help. If you have a chance, please give it a try when it is available and let me know if the problem still occurs. If so, the information in the log file will likely help us to track down the cause of the problem.
     
    superpig likes this.
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @skuami: You are likely seeing Unity fall back to the system default editor because Visual Studio 2013 is busy immediately after it is started. Please try 4.5.3p1 when it is ready and let me know if the problem persists.
     
  14. skuami

    skuami

    Joined:
    Jul 16, 2013
    Posts:
    5
    Thanks Josh!

    Here's an other hint for trouble shooting:

    I just installed the UnityVS tools (it is free since MS bought the company behinde the tools) and it works again. Now I am able to double click on a script file in unity and it opens visual studio correctly.

    I still run Unity 4.5.2.f1 and VS2013 Premium.

    In other words, the UnityVS tools solved my VS problem. ;-)
     
  15. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    for what it's worth, I had the same issue after cleaning my registry, but I realized that it still works, I just needed to run Unity in administrator mode. Using Windows 7 and an up-to-date Unity. Hope this helps other people as well :)
     
    omegasbk likes this.
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @skuami: I'm glad to see that UnityVS worked for you. I suspect that this works around the problem because UnityVS adds a new entry in the External Script Editor preference (UnityVS.OpenFile). Please let us know if you run into problems in the future.
     
  17. Dagra

    Dagra

    Joined:
    Nov 8, 2012
    Posts:
    4
    I started experiencing this issues with version 4.6.0b20 and VS 2010 Ultimate. Everything has been working fine for months and out of the blue it just started saying it was opening VS and opened Mono Develop instead.

    I found if I open the project in VS 1st it will open the scripts in VS like normal, but if VS is not open or the project is not already open in VS it will not.
     
  18. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    This is happening again in 4.6
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    Can you provide the Editor.log file when this problem happens here or submit a bug and let me know the bug number? We now have a good bit of logging for these cases in the Editor.log. That should help us track down the cause of the problem. Thanks.
     
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    As I mentioned to Dagra, please provide the Editor.log or submit a bug when this happens. With the logging we have enabled we should be able to find and correct the cause of the problem. Thanks.
     
  21. Naliwe

    Naliwe

    Joined:
    Mar 9, 2015
    Posts:
    1
    Hi, I've been having the same problem since I started using Unity (4.5.i can't remember ) with VS 2013. I am now using Unity 5, and had the same problem. I read those posts while trying to figure out what to do ( after trying to re install Windows and VS and Unity, which is kind of an overkill, but I had to do it anyway so ... all those efforts to no avail though ). I finally managed to make it work : I unchecked the Editor Attaching box just under the External Editor drop down list. Not sure what it does nor if I need it, but now it works fine with VS 2013 and ReSharper.
    Hope that helped !
    Regards.
     
  22. RetroTK2

    RetroTK2

    Joined:
    Mar 9, 2013
    Posts:
    3
    @Naliwe Thank you so much for this man, been having this problem for ages :)
     
  23. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    I have some simular issues. @Naliwe 's suggestion helped but now when I double click an error or warning, Unity opens Visual Studio in a new instance and the solution is empty. If I go via Menu -> Visual Studio Tools -> Open in Visual Studio I have the whole solution. Before I upgraded to Unity 5.0 it behaved correctly.
     
  24. StarFluke

    StarFluke

    Joined:
    Jan 19, 2013
    Posts:
    39
    Have Visual Studio 2015 sp1. After upgrading from Unity 5.2.3f1 to 5.3.0f4 I began seeing this problem: "....started saying it was opening VS and opened Mono Develop instead...."
    I upgraded to 5.3.1f1 and I am still seeing the same problem with an extra symptom:
    Now Visual Studio must Migrate the project to the current Visual Studio version. While the version upgrade is in process, Mono Develop opens.
    Other observations I see:
    The VsHub.exe tree of processes gets started. (Looks normal)
    devenv.exe gets started and just silently idles.
    The new devenv (2015sp1) includes a child process named PerfWatson2.exe when started manually; the Unity kick off never includes this child process.

    A workaround exists:
    Manually open Visual Studio and open the Unity project. Now double clicking a file will open it in Visual Studio but the whole project has to be migrated each time... it appears Unity is not accepting the Visual Studio Migration changes.
     
  25. hugolcouto

    hugolcouto

    Joined:
    Jul 19, 2015
    Posts:
    5
    I'm updated both the Unity and VS2015, but it still doesn't work. The weird is because a couple of days ago it was working. Now Unity opens MonoDevelop instead and it stuck in a screen saying it's opening the Visual Studio.

    Also, when the MonoDevelop opens, it shows a message saying "Could not load project <name script>.CSharp.csproj with unknow type..."


    What could it be?
     
  26. k0mbain

    k0mbain

    Joined:
    Nov 1, 2012
    Posts:
    22
    I realized that this bug occurs when ReSharper is enabled in VS (or probably other heavy-load extension). When I disable ReSharper VS loads normally.

    I posted a question i VSTU Gallery:
    and gathered such answer:
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @k0mbain

    Can you submit a bug report via Unity for this issue? Note that Unity logs some information in the Editor.log file when its timeout waiting for Visual Studio expires, so that log file might have more helpful details. The log file will be submitted along with the bug report so we can review it.
     
  28. k0mbain

    k0mbain

    Joined:
    Nov 1, 2012
    Posts:
    22
    Hi @JoshPeterson , I already did it, but I'm not sure if I reproduced bug when I sent the report. In that case I'm sending it here. The ticket case is: 818526_e66q7bon1tb688g6
    The log file is attached to this post.
     

    Attached Files:

  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @k0mbain

    Thanks for the information. I've linked to this editor log file in the bug report. We will investigate it.
     
  30. k0mbain

    k0mbain

    Joined:
    Nov 1, 2012
    Posts:
    22
    I was asked by QA team to test if this bug occurs in Unity 5.3.6f1 and surprisingly it's not. Visual Studio is opening properly in this version of Unity.
     
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @k0mbain

    I'm glad to hear that! I don't think that we made any changes to correct it though, so maybe the timing just happens to work now. Please keep an eye on this and let us know if it shows up again.
     
  32. k0mbain

    k0mbain

    Joined:
    Nov 1, 2012
    Posts:
    22
    @JoshPeterson
    I will for sure :)

    I can confirm that in Unity 5.4.0f3 all works good.
    I observed something weird. I had previously installed Unity 5.3.4p1, then as I said before, I was asked to check it out in 5.3.6f1 which I installed on second hard drive without reinstalling old version. Then, after confirming this is not occuring in 5.3.6f1 I uninstalled it and run older 5.3.4p1 (without installation, I had it on another disk), which supprisingly started working properly. It seems like installer of newer version changed something in my OS or in a place shared between Unity versions. I did'nt installed Visual Studio Tools for Unity from Unity installer because I had newest 2.3 version already installed from Visual Studio Gallery. So it seems something changed timings permamently in 5.3.6f1.
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @k0mbain

    That does seem rather odd. I can't explain why installing 5.3.6f1 would have any impact, sorry.
     
  34. mbpakalin

    mbpakalin

    Joined:
    Aug 30, 2016
    Posts:
    2
    I cant believe that, running unity with administrator privileges worked!
     
  35. houserrob

    houserrob

    Joined:
    Mar 26, 2013
    Posts:
    2
    I just found myself hitting this problem as well. I've been using Unity 5.3.5 successfully with VS for some time now ( a month or more ) and just suddenly I cannot get VS to launch. I'd not rebooted, nor installed anything I'd been using it earlier now it just won't launch. The trigger for me appears to have been my first build of an Android project rather than Windows. I've tried the suggestions here of running Unity as admin, renaming MonoDevelop, and manually specifying devenv.exe's path but that doesn't get me back to where the solution loads properly and I can debug in VS. A reboot didn't change anything. Does anyone have any ideas what else I can try?
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @houserrob

    Have a look at the editor log file immediately after to try to open Visual Studio. The editor should output information about the various things it is trying to start Visual Studio. You can reply here with the details from the log, and maybe we can track down the cause of the problem.
     
  37. yonshi

    yonshi

    Joined:
    Nov 14, 2016
    Posts:
    1
  38. Rajan95

    Rajan95

    Joined:
    Jun 7, 2019
    Posts:
    7
    Hi I'm having a similar problem! Using Unity 2019.2.3, trying to open a Visual Studio script but xcode opens instead.
     
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    I suspect that Preferences in the Unity Editor cannot find the script editor, so it is falling back to the system to determine how to open a .cs file. You might want to check the Preferences in the Unity Editor first, then modify your system editor for .cs files.
     
  40. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,472
    still not work. vs 2019 and unity 2020.1.9f1
     
    EmilKoel likes this.
  41. chesiq

    chesiq

    Joined:
    Apr 25, 2015
    Posts:
    5
    Found an issue in 2019.4.13f1
    After some time - double-clicking on a script in the inspector does not open up VS(as if you don't have source files). Double-clicking in project browser works. Also right-clicking and -> edit script works.
    Weird, seems there is an issue where editor is determining if it can open VS and/or if it has source file, or as usual it's just an editor visual bug because some data did not reach view or got updated and thus did not leave state (disabled).
     
  42. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    amesa_unity likes this.
  43. amesa_unity

    amesa_unity

    Joined:
    Oct 16, 2019
    Posts:
    5