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

Using Visual Studio Express with Unity instead of Mono Develop

Discussion in 'Scripting' started by BogTurtleGamesLLC, Jan 14, 2014.

  1. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Hello,

    I recently downloaded the latest Unity for evaluation purposes and it seems great. Although Mono Develop seems pretty good, there are enough quirks when using it that I opted to try Visual Studio Express instead (i.e., either Visual C# Express or Windows Desktop Express).

    There are many threads on these forums wondering how the integration between Unity and Visual Studio Express could be better. Instead of replying to all those threads, I decided to create this one.

    I have developed a simple application that acts as a middleman between Unity and Visual Studio Express. Although not perfect, it is able to open a project in Visual Studio Express when you double-click on a script file in Unity. In other words, the project doesn't already need to be open in Visual Studio Express for this to work. It is also able to go to the correct line number in Visual Studio Express if you double-click on an error in Unity.

    I hope it is helpful to some of you - tell me if you have any problems with it. The source is on github:

    https://github.com/BogTurtleGamesLLC/UnityVSExpress

    Carl Erikson
    Bog Turtle Games LLC
    http://www.bogturtlegames.com
     
    Last edited: Jan 14, 2014
    EliasMasche likes this.
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I'm sorry if I don't understand... But I don't have your tool and Unity already open VS Express for me when I double-click a script file.

    All I had to do was to select Visual Studio Express from the External Script Editor field in External Tools in the preferences.
     
    Magiichan likes this.
  3. Deleted User

    Deleted User

    Guest

    just tried it and the go to line part works great. Sadly it always still opens a new Visual Studio Instance. However I appreciate your work
     
  4. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    is there a way to fix this or is this an vs express limitation?
     
  5. Khalanar_Dev

    Khalanar_Dev

    Joined:
    Mar 25, 2013
    Posts:
    34
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I don't have VS Pro at home, and it still opens VS Express when I click a script. They list two way to setup VS Express vs VS Pro, and yet you can do the same for both.

    That's the way I did it with VS Express, and it works.
     
  7. Deleted User

    Deleted User

    Guest

    yes its the same way I did it. However if you doubleclick a script or error message inside Unity it will always open a new Visual Studio instance, it will not go to line (in case of error), and it is not your VS solution that gets opened only, the script itself.

    Normally I sync my Unity Project ( Assets -> Sync MonoDevelop Project ), to get my VS solution up and running ...
     
  8. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    does it open the current solution when you double click on a file in unity? or does it open in a new instance like element_wsc described?
    does it jump to a file and line when you double click on a error/debug log entry in unity?
    which express version do you use?
     
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    New instance. Is this what this tool does? Prevent multiple instance from opening? If so, the description wasn't very clear.
     
  10. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Please tell me the issues you are having with the UnityVSExpress application. There are some cases where it will not work, but most of the time it does. For example, if you have no Visual Studio Express open, the application should open a new instance of Visual Studio Express and open your solution and file. If you already have a Visual Studio Express instance open, it should open the file in that instance. Note that if you have multiple Visual Studio Express instances open, then it is not guaranteed which instance the file will open in.

    If this behavior is not what you are experiencing, then please give me more details.

    PS - Sorry for the late reply - I am new to this forum and wasn't subscribed to this thread. I'll be more responsive in the future.
     
    Last edited: Jan 16, 2014
    EliasMasche likes this.
  11. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,615
    Well it's opening the project rather than just the file (a part of which is the instance management stuff) and it's got go-to-line support for log messages.
     
  12. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    One more thing. The UnityVSExpress app won't work properly if you already have an instance of Visual Studio Express up and running that is not open to your Unity project. I'll see if that quirk can be eliminated, but for now that's how it is.
     
    EliasMasche likes this.
  13. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    if your tool is capable of all those functionality it seems that the unity to vs-express limitations mentioned on the site linked by Pablo Sánchez are not VS inherent. so i wonder why UT does not support it out of the box.
    anyway good work and its surely a help for many devs as these limitations are the only reason (beside the debug thing) to not use visual studio express for developing. and as monodevelop has grown to a serious nightmare from what i read there is dire need for an alternative.
     
  14. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,615
    While there are a few known workarounds, I think that doing it via the official SDK is VS dependent. So it's perhaps that Unity can't do it in any way that they can officially support?

    And while this is a significant improvement over the built in Express usage (which treats it like a dumb text editor), from what I see it still has issues that may only be solvable with the official SDK that kind of rule it out as being an official feature anyway (like loading multiple instances if you don't use it exactly right).
     
  15. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    It doesn't go to line on professional either after it has initially opened a script.
    You have to wait till it has opened, then click the error message again in unity and it will go to line.
    Are you saying with express it just keeps opening new instances of VS for the same script?
     
  16. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    For anyone having problems with the UnityVSExpress app opening new instances all the time, make sure you specify the Visual Studio Express year as the third parameter and see if that fixes anything. Currently, the app defaults to 2010 (i.e., Visual C# Express 2010). For example, if you are using the latest Visual Studio Express (Windows Desktop Express 2013), then your external editor args in Unity would be:

    "$(File)" $(Line) 2013

    Note that you still can't debug using Visual Studio Express. However, if you need debugging you can switch back to Mono Develop temporarily. At least that is what I was planning to do.
     
  17. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    The UnityVSExpress app is really just a quick hack intended to make Visual Studio Express work a little better with Unity. It is definitely not up to snuff in terms of being an "official" solution.
     
  18. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Added a section in the github readme that specifies some troubleshooting actions you might take if UnityVSExpress is not working for you.
     
  19. Giometric

    Giometric

    Joined:
    Dec 20, 2011
    Posts:
    170
    This works great! Using it with Visual Studio Express 2012. I did make some small changes to the source to fix the fact that this tries to open the full Unity solution (which includes *.unityproj files that VS can't open). Now it opens the [ProjectName]-csharp.sln; it worked before anyway, but this at least gets rid of the error message the first time you open it.

    In Program.cs:

    At line 219:
    Code (csharp):
    1.  
    2. string expressTitle = unityRootDir.Name + "-csharp" + expressTitleEnding;
    3.  
    And at line 244:
    Code (csharp):
    1.  
    2. psInfo.Arguments = "\"" + unityRootDir.FullName + Path.DirectorySeparatorChar + unityRootDir.Name + "-csharp.sln\" \"" + scriptName + "\"";
    3.  
     
  20. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Thanks for the fix! I added similar code to the github repo.
     
  21. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,615
    Oh, I realise that, which is what I was trying to explain to exiguous. It's super handy (just giving it a whirl myself right now) but it's not the kind of thing that Unity probably want to include themselves.

    Thanks for sharing, by the way! :D
     
  22. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    If you selected Assets-->Sync MonoDevelop Project from Unity, it would crash UnityVSExpress. I think I fixed that bug with the latest commit (see github).
     
  23. _MoP_

    _MoP_

    Joined:
    Mar 19, 2014
    Posts:
    2
    This is really useful!

    I'm having a small issue (workaroundable) that seems like it should be fixable though, although my Windows-code-fu is not strong enough...

    Basically, if I don't add 2012 to the end of the command line in Preferences (using VS Express 2012), it will only open the a single .cs file and not the whole Solution in VS.
    However, with the 2012 appended, the first time it will load the whole Solution (which is great!) - but then every next time you double-click on a script file in Unity it will launch a new VS instance.
    The interesting thing is that, after launching for the first time, if I remove the "2012" from the command line in Preferences, double-clicking on script files in Unity will open them correctly in the currently-running instance!

    So that's my workaround for now - launch it the first time then remove the "2012" from the command line, and it all works exactly how I'd expect :)

    Any way to ensure this is the default behaviour (e.g. don't open a new instance of VS if one is already running?)
     
  24. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    I'm glad that you are using it and sorry that it isn't working like it should.

    If you do not specify a year, it defaults to 2010. Do you have 2010 Visual Studio Express installed on your machine? From what you are describing, I am guessing the answer is no. In this case, UnityVSExpress will attempt to find 2010, fail, and then default to opening up the single .cs file using the default Visual Studio Express application (for you, 2012). So this makes sense to me.

    The first part makes sense to me. UnityVSExpress locates your 2012 install directory and runs WDExpress.exe from it to open up the entire solution. However, it shouldn't be opening a new instance if one is already open. So this implies to me that the IsSolutionOpen() function is returning false on your machine when it should be returning true. UnityVSExpress tries to determine if a solution is already open by checking the titlebars of running processes. So maybe the titlebar on your machine is different than what I am expecting. If you could tell me what your titlebar says in its entirety, it might help me fix the problem. An example of a complete titlebar might be something like:

    MyGame-csharp - Microsoft Visual C# 2010 Express

    The last part makes sense too. When you remove the 2012, UnityVSExpress will not find 2010 on your machine and so will skip the IsSolutionOpen() check completely and just open up the .cs file. Because your project is already open, the file will be opened in that Visual Studio Express instance.
     
    Last edited: Mar 20, 2014
  25. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Even though this probably isn't the problem, I'll just throw it out there for completeness. UnityVSExpress assumes you only have one Assets folder in your Unity folder structure and it is at the top level inside your project. It also assumes that all your scripts are located somewhere within this Assets folder. If this is not the case, it could cause issues.
     
  26. NTDC-DEV

    NTDC-DEV

    Joined:
    Jul 22, 2010
    Posts:
    593
    Just wanted to say that this is awesome! Should be stock with Unity.

    So far, it works great, been using VS Express 2013 Desktop.

    Thanks again!
     
  27. riks43

    riks43

    Joined:
    Apr 2, 2014
    Posts:
    1
    Hi and thank you for your script.

    Concerning this problem :

    I check your code and see you search in the windows title but, it work only for english version of windows.

    I made a fix who just search visual studio process and verify the windows title contain unity projet name.

    You can found here : http://pastebin.com/82UDJam0 sorry for the pastbin i don't have GitHub account.

    Can you confirm it produce no regression ? i just test with french version of visual studio express 2012.
     
    Last edited: Apr 2, 2014
  28. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    953
    The following solution is working fantastically for me:
    http://www.pipefantasy.com/?p=1303

    Essentially with this technique you replace the MonoDevelop.exe file with a custom built one which simply reroutes each "Open Source File" request to open using Visual Studio Express instead of MonoDevelop. It can even open source files at specific lines when double-clicking lines using the inspector.

    I hope that this is as useful for others as it has been for me :)
     
  29. Deleted User

    Deleted User

    Guest

    wow. this one work great! Awsome and thanks
     
  30. BogTurtleGamesLLC

    BogTurtleGamesLLC

    Joined:
    Jan 14, 2014
    Posts:
    11
    Sorry for the late reply.

    Thanks for the code. I modified your changes slightly and I updated the repo. I uncommented the GotoLineInSolution line - that should work for you now. I had to make a string equality test in your code case insensitive in order to make it work on my machine. Hopefully it still works for you now.
     
  31. begem0t

    begem0t

    Joined:
    Jul 1, 2013
    Posts:
    4
    Works great on VS Express 2013. Kudos!
     
  32. gabra

    gabra

    Joined:
    May 15, 2014
    Posts:
    1
    Thanks!! working with VS Express 2013!
    :D
     
  33. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,615
    Just wanted to pop in and say, using this again for some tinkering.
     
  34. Tien-Tran

    Tien-Tran

    Joined:
    Nov 19, 2012
    Posts:
    2
    working with vs 2013, thank you so much
     
  35. Botaurus

    Botaurus

    Joined:
    Feb 20, 2013
    Posts:
    81
    I can not get this to work. I setup everything correctly, but when I double click a script, nothing happens.

    I tried debugging the program. I added dummy args...
    args = new string[3];
    args[0] = "C:\\Path\\To\\Script";// script inside a unity project
    args[1] = "12";
    args[2] = "2013";

    and when I debug, I get an error:
    Additional information: A 32 bit processes cannot access modules of a 64 bit process.
    at line 219.
    I don't know how to compile or debug a c# program so Im sure my attempt was useless. But anyways, this would be awesome to get working! Thanks!
     
  36. Alchemy_Fire

    Alchemy_Fire

    Joined:
    Aug 27, 2013
    Posts:
    14
    @dannyUNITY3d,

    If you are trying to use this with the Unity 5 beta 64 bit editor (as I have been doing this morning), you will need to recompile UnityVSExpress as a 64 bit program (in VS, right click the project file, properties, build tab, set platform target to x64).

    @BogTurtleGamesLLC / @Giometric - Thanks for the tool - works great!
     
  37. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    For me this works great initially, but then if I click on an error it only goes to the line if that current file is active. I'm guessing maybe there's some macro keys not working correctly? I don't know enough about visual studio to look into macro keymapping and what it is you're doing in the GotoLineInSolution() call. I'd love to get this working.
     
  38. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    It's the SetForegoundWindow( handle ); that's not working for me I believe. If the file is already in the foreground it works fine. If the file isn't open it works fine. If the solution isn't open, it works fine. But if the file is open and not in the foreground, the foreground isn't changed and the macro will try to go to the line in that file. Luckily my current file had less lines and I was able to catch this wasn't working.
     
  39. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Spare yourself a trouble and get Pro not express
     
  40. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I applied for Bizpark so hopefully I can. If not then I need this solved.
     
  41. Deleted User

    Deleted User

    Guest

    I just got my ok from @Dave_Voyles , Thanks again Dave. And I wish you, jtsmith, good luck to get in there. What an awsome programm BizSpak is. Never Mono-Develop again
     
  42. slay_mithos

    slay_mithos

    Joined:
    Nov 5, 2014
    Posts:
    130
    I used to develop with the full suite of the ultimate version, and resharper on top of this, but that was as a student, the licenses for those now are just way too pricy for it to be accessible by your average hobbyist...

    In the mean time, I'll keep using Mono Develop, because I certainly am not going to put as much as a small computer for just the "pro" version, and more than my best gaming rig for the ultimate, for something I "only" use on my personal free time right now.

    A bit sad, because it's definitely true that all those additional tools help a great deal, in all of the steps.

    But it's definitely good to know that it is a possibility to use it for those that have access to a license.
     
  43. Gooseman_1977

    Gooseman_1977

    Joined:
    Aug 15, 2013
    Posts:
    89
    ooh nice. Thanks for this mate. I can't wait to ditch MonoDevelop..
     
  44. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    maybe you can use VSCommunity. Sounds like it allows the use of plugins (UnityVS) and is free.
    read about it here.
     
    NTDC-DEV likes this.
  45. slay_mithos

    slay_mithos

    Joined:
    Nov 5, 2014
    Posts:
    130
    It definitely feels like a good base tool, but for people that worked for nearly 10 years in the complete package of the ultimate edition, I wonder if the part that are lacking won't be even more glaring than when you work in a different IDE like mono?
     
  46. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    353
    Wanted to thanks for the program, works perfect.
     
  47. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Has anyone tried using the VS Profiler in place of the Unity profiler?
     
  48. Play4FreedomDE

    Play4FreedomDE

    Joined:
    Jul 2, 2015
    Posts:
    2
    thank you this helped a lot
     
  49. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    953
    Unity works perfectly fine with Visual Studio Community and Visual Studio Pro; hence there is no need for any hackarounds anymore; it just works :D

    You may want to look into the Visual Studio 2015 Tools for Unity package if you haven't already since this provides a richer Unity development experience within Visual Studio.