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

Generate .sln/.csproj without Visual Studio

Discussion in 'Scripting' started by LitchiSzu, May 12, 2018.

  1. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    Hi there!

    I've been using VS Code for more than a year now but I used to also have Visual Studio installed, which I don't do on all computers anymore.
    I realised recently (by making new projects) that if VS Code is selected as the preferred editor for Unity, no sln/csproj will be generated, even using the Edit -> Open C# Project action.

    Only way to get them to be generated is to switch the preferred editor to Visual Studio and to use the Open C# Project action or to double click a C# file in the project.
    I can deal with that (eventhough it's quite annoying...) but I would love to not have to install Visual Studio everywhere. I always have the build tools installed (for C++ reasons, but I still install msbuild and .NET for C# anyway) but I don't really want to install Visual Studio while I am not using it.

    Is there any alternative to generate the solution files please ? I need them for Omnisharp (in VS Code) to enable Intellisense.

    Thanks!

    PS: I'm on Windows, in case it matters.
     
    matkoniecz likes this.
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,514
    Generate the solution files on the machine with Visual Studio. Then submit those solution/proj files to whatever version control/repository system you use for you shared project. And the other machines will get it, while not needing Visual Studio.
     
  3. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    Thank you but, clearly we are not facing the wall with this problem and we are already using this alternative.
    However it still is annoying when someone has to create a new project on a computer without VS.

    I am only looking for a way to generate these files without VS on the computer or at least without having to switch the preferred editor in the Preferences.
     
    matkoniecz likes this.
  4. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    Bumping that up as I didn't get any reply.
    I want to be able to generate the csprojs file without switching to Visual Studio for that.

    I'm going to write some tool to do it, but if there is a way to do it from the engine, it would be great. Or, if there is some specification for me as to which file types I need to include for it to be similar to Unity's (I've seen it include .cs, .shader, .compute but unsure what else!)
    It would also help to be able to regenerate them easily on the fly so that when people add files to the project they can regenerate their csproj themselves : )

    Thanks,

    Clem
     
    matkoniecz likes this.
  5. Dance_M

    Dance_M

    Joined:
    Aug 17, 2014
    Posts:
    15
    Same here. No *.sln; *.csproj files generation in latest Unity version, which is critical for Sublime Text users. I cannot find any solution except manual switching to VS, building, and switching back to ST. That is terrible :(
     
    matkoniecz likes this.
  6. Jakintosh

    Jakintosh

    Joined:
    Jan 26, 2014
    Posts:
    6
    Agreed. I've been struggling to keep sublime text 3 as my default editor, but it just gets harder and harder. I've had to resort to jumping back and forth to VS to generate the .sln files and it's really a huge pain. VS eats resources on my machine like nobody's business, I really wish I didn't have to rely on it.
     
    matkoniecz and Dance_M like this.
  7. rad1c

    rad1c

    Joined:
    Feb 26, 2016
    Posts:
    21
    What worked for me was Edit -> Preferences -> External Tools, and I set VSCode up here by "Browse..."-ing the VSCode executable.
    As soon as it's set, sln and project files are generated, OmniSharp is loaded up, etc, so everything works like charm (beforehand, with 'open by file extension' setting, even though VS Code started as the script editor, the sln and project files were not created by Unity).

    Hope this helps.
     
    Last edited: Jul 13, 2018
    yaadm likes this.
  8. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    @rad1c Thanks but eventhough it used to work for me before 2018, it doesn't anymore. I definitely have it set as my code editor in Unity, it opens the files correctly, on the correct line, but it won't create any project file : (
     
  9. rad1c

    rad1c

    Joined:
    Feb 26, 2016
    Posts:
    21
    @LitchiSzu
    Huhh. Weird. Are you sure the setting is correct? Here's how it looks like for me: setting.jpg

    It didn't work for me either until I explicitly pointed to vscode's exe file (see Script editor is "named").
    If it looks like that for you, you could try pointing at the exe again maybe?
     
  10. LitchiSzu

    LitchiSzu

    Joined:
    May 14, 2016
    Posts:
    17
    @rad1c Yes, 100% sure, but I now know what the problem was.
    Unity, for some (really bad) reasons, decides to generate the sln and project files depending on the name of the code editor set in preferences. And it assumes (wrongly) that if you are not using something from their list, you don't want sln files.
    Problem is that, I was using VSCode Insiders and the executable name is not what Unity expects. Renaming the exe to code.exe fixes the problem.

    So guys, if you need sln files for Omnisharp with anything, just rename your executable to code.exe!
    Yes it's a really dodgy work around.

    I made this suggestion that you can upvote to hopefully have something better:
    https://feedback.unity3d.com/suggestions/option-to-let-user-generate-solution-and-project-files
     
  11. Dance_M

    Dance_M

    Joined:
    Aug 17, 2014
    Posts:
    15
    Yep, it works. Unfortunately, Unity disable custom command line arguments for external editor (code.exe) and because of this on each appeal to a script from logs window Sublime Text open new window instead of using the existing one :(
    Stupid bug, hate it.
     
  12. TKdevlop

    TKdevlop

    Joined:
    Aug 2, 2018
    Posts:
    1
    Love you bro you don't know how much I google this S*** going even up to the second page.
     
  13. yaadm

    yaadm

    Joined:
    Oct 10, 2016
    Posts:
    1
    This is the right way to do it.
    Thank you.
     
  14. TITOU2B

    TITOU2B

    Joined:
    Jan 2, 2021
    Posts:
    1
    Since, I don't know when you can simply go to Edit -> Preferences -> External tools and select everything under "Generate .csproj files for:" and just clic on Regenerate project files. ;p that worked for me after testing it out!