Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[SOLVED] Unity not generating .sln file from Assets > Open C# Project

Discussion in 'Editor & General Support' started by Stardog, Jun 30, 2018.

  1. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,890
    Last edited: May 11, 2020
  2. asp_kom

    asp_kom

    Joined:
    Aug 23, 2013
    Posts:
    3
    It is 2020. 2 years. Still not fixed. Such a shame.
     
    qibinyi, EyeDev44, PlanarBit and 4 others like this.
  3. Flexford

    Flexford

    Joined:
    Dec 8, 2016
    Posts:
    20
    My solution
     

    Attached Files:

  4. sebulan

    sebulan

    Joined:
    May 7, 2020
    Posts:
    1
    Man I know it's been almost two years since you posted this, but you saved my night, so I thank you
     
  5. idbrii

    idbrii

    Joined:
    Aug 18, 2014
    Posts:
    51
    Reposting a summary of Flexford's answer so you can see what it's doing and this page shows up in SyncVS search results (but the .cs is a more robust solution):

    Code (CSharp):
    1. [UnityEditor.MenuItem("Assets/Regen Sln", false, 1000)]
    2. public static void RegenerateSolution()
    3. {
    4.     var sync_vs_type = Type.GetType("UnityEditor.SyncVS,UnityEditor");
    5.  
    6.     var synchronizer_field = sync_vs_type.GetField("Synchronizer", BindingFlags.NonPublic | BindingFlags.Static);
    7.     var sync_solution_mi = sync_vs_type.GetMethod("SyncSolution", BindingFlags.Public | BindingFlags.Static);
    8.    
    9.     var synchronizer_object = synchronizer_field.GetValue(sync_vs_type);
    10.     var synchronizer_type = synchronizer_object.GetType();
    11.     var synchronizer_sync_mi = synchronizer_type.GetMethod("Sync", BindingFlags.Public | BindingFlags.Instance);
    12.  
    13.     sync_solution_mi.Invoke(null, null);
    14.     synchronizer_sync_mi.Invoke(synchronizer_object, null);
    15. }
    16.  
    You can see that Unity is intentionally preventing sln generation for "other" editor types:
    https://github.com/Unity-Technologi...b/master/Editor/Mono/CodeEditor/SyncVS.cs#L25
    So this code calls both the "Open C# Project" (SyncSolution) and the bit in the if block (Sync).
     
    Qray5000 likes this.
  6. tobia537

    tobia537

    Joined:
    Mar 24, 2013
    Posts:
    1
    Thank you man. This worked out!
     
  7. spycarrot

    spycarrot

    Joined:
    Feb 20, 2015
    Posts:
    8
    2021 still reproing this issue
     
    Drakoran and PorkNChop like this.
  8. LilHati

    LilHati

    Joined:
    May 12, 2018
    Posts:
    3
    This fixed it for me as well.

    I believe this issue arose for me when I had reinstalled VS 2019 a couple time because I was having an issue with some Python configuration (for an unrelated, non-unity project). My guess is that the multiple install/reinstall process broke the link between VS 2019 and Unity.
     
    Diskomuz likes this.
  9. Markisha64

    Markisha64

    Joined:
    Oct 16, 2021
    Posts:
    1
  10. deltameta

    deltameta

    Joined:
    Nov 30, 2020
    Posts:
    5
    I bit the bullet and downloaded the full Visual Studio for Mac. I gave up on Visual Studio Code after a few hours of going in frustrating circles and trying several suggestions on the Unity forum and StackOverflow that didn't work.

    One thing I noticed right off the bat is that the Visual Studio installation will automatically prompt you to download the necessary .NET stuff. I didn't have to run any commands to install things once Visual Studio was installed (although, I did download the dotnet and Mono installations previously for VS Code, so who knows if these were used or not...).

    Once Visual Studio for Mac is installed, I went into Unity and gave Visual Studio Code the ol' boot by updating my preferences to open Visual Studio as my external editor:
    Unity version: 2020.3
    Unity > Preferences > External Tools > External Script Editor > Visual Studio for Mac [8.10.11]
    I've also got Package Manager > Visual Studio Editor installed (2.0.11)

    Finally, I opened my .cs file from within Unity (alternatively, you can right-click and select Open C# Project). Once Visual Studio opened:
    Visual Studio > Preferences > Theme > Dark (we aren't barbarians...)
    ...and then File > Open > and opened my Unity game .sln file.
    I went to the script in question to try things out and badda-bing-badda-boom, intellisense and all my stuff worked and opened without a hitch.

    Best of luck.
     
    TitikUniverse and nesh34 like this.
  11. mcaldei01

    mcaldei01

    Joined:
    Dec 8, 2017
    Posts:
    12
    Use this steps to solve it.

    First Step:

    - Check that Unity > Preferences > External Tools > External Script Editor > Visual Studio option is selected.
    (Note: you must have "Visual Studio tools for unity" installed) ... but that should have been done automatically when you installed unity with visual studio, so if you want, jump to the next step.

    Try and see if it works. If still does not work, go to next Step:

    Second Step:

    - Exit visual studio.
    - Go to Unity > Preferences > External Tools ... and click the Regenerate Project Files button.

    Open a c# script in unity, it should work now.

    (I am using visual studio 19 (16.10.4) and Unity version (2020.3.14f1))
    Hope this help guys !
    Good Devs.
     
    MrUndead, mngmhds, Mortichar and 4 others like this.
  12. fahadshafique

    fahadshafique

    Joined:
    Aug 25, 2015
    Posts:
    3
    my problem resolved this way.Thanks
     
    mcaldei01 likes this.
  13. clooper

    clooper

    Joined:
    Jul 22, 2013
    Posts:
    7
    Ran into this problem for the first time today. My problem was that there were old Visual Studio solution files and cs project files in my projects root directory. I discovered that these needed to be deleted *before* I did the following (otherwise the situation got even worse)

    After deleting the files I set this:

    Preferences > External Tools > Generate .csproj files for >
    Embedded Packages (checked)
    Local packages (checked)
    Player Projects (checked)

    And then pressed the "Regenerate project files" button.

    New versions of the deleted files were regenerated, but were now compatible with the updated Unity Editor and the updated Visual Studio Editor.
     
  14. dan_ginovker

    dan_ginovker

    Joined:
    Jun 13, 2021
    Posts:
    76
    '"Regenerate project files" not showing up for anyone else? Unity 2020.3.30f1, Linux version
     
  15. C_Blue

    C_Blue

    Joined:
    May 28, 2022
    Posts:
    1
    Yup, no such option. Cannot/does not generate csproj nor sln files, no such options.
    Using Unity, Mono completely installed and verifiedly working, and VSCodium (no telemetry).
     
    InfimaLabsAnthony likes this.
  16. cruizdec43

    cruizdec43

    Joined:
    Jan 10, 2022
    Posts:
    2
    Hi, sorry for the bump on this, but I have updated to Unity 2021.3.3f and this stopped working:

    NullReferenceException: Object reference not set to an instance of an object
    325 at ...SyncSolutionUtilities..cctor () [0x0003b] in D:\...\SyncSolutionUtilities.cs:30

    These lines are the issue:

    _syncVSType = Type.GetType("UnityEditor.SyncVS,UnityEditor");
    _synchronizerField = _syncVSType.GetField("Synchronizer", BindingFlags.NonPublic | BindingFlags.Static);

    but I have no clue on how to fix it.

    Can someone help me?
     
  17. cruizdec43

    cruizdec43

    Joined:
    Jan 10, 2022
    Posts:
    2

    For anyone losing their minds like I did: I started reworking the script, which completely worked both through terminal and by manual trigger in my local machine, but somehow never worked on my CI pipeline. I was using 2021.3.3f1. I attached the file in here just in case it works for anyone, but I made it work also on my CI was by using this Jenkins script: https://docs.unity3d.com/Packages/c...using-the-jetbrains-rider-editor-package.html
     

    Attached Files:

  18. JBVirt

    JBVirt

    Joined:
    Jul 18, 2022
    Posts:
    2
    There is a comma in "UnityEditor.SyncVS,UnityEditor"
    It should be a period. But mor importantly should not have ",UnityEditor". at the end.
     
  19. AkilliMum

    AkilliMum

    Joined:
    Dec 6, 2014
    Posts:
    107
    I always run into this issue :) You have to install VSEditor package from package manager :)
    upload_2023-4-29_12-29-10.png
     
    LordRock, neonblitzer, PasVol and 6 others like this.
  20. pjch54252

    pjch54252

    Joined:
    Apr 18, 2022
    Posts:
    1
    This works for me. I made a project not myself from example project, that's why I didn't have this package!
     
  21. Orion336

    Orion336

    Joined:
    Feb 17, 2019
    Posts:
    2
    @SkilliMum, Thank you so much! I hardly ever use the package manager and your screenshot helped me find the unity registry. Feel stupid for not finding it before but it solved my issue instantly.