Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Visual Studio: the following files were specified on the command line ....sln

Discussion in 'Code Editors & IDEs' started by Louis_Amerongen, May 26, 2018.

Thread Status:
Not open for further replies.
  1. Louis_Amerongen

    Louis_Amerongen

    Joined:
    Jul 21, 2017
    Posts:
    19
    Hi,

    When I try to edit a cs file in Visual Studio from Unity, I get the message:
    The following files were specified on the command line ....sln These files could not be found and will not be loaded.

    Further in Visual Studio, Unity variables are not completed.

    What am I doing wrong?


    Thanks in advance,

    Louis
     
    hopetolive likes this.
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    It sounds like your project file is messed up.
    That error does often occur if a file has been deleted (or renamed) externally, i.e. the project file does still have an entry for that file and attempts to find it. The project file does not recognize changes that are done externally and cannot update its list of included .cs files.

    Make sure the file does exist with the exact same name, or enable the "Show all files" option and try to remove it in the solution explorer and add the actual file, if necessary.
    If that doesn't work, you could still remove the file-entry by editing the project file manually, but make sure you do not mess up the project file.

    Another option would be to delete the project file (make a backup before you do such things) and let Unity recreate it for you.
     
  3. Louis_Amerongen

    Louis_Amerongen

    Joined:
    Jul 21, 2017
    Posts:
    19
    Thanks for you're answer Suddoha,

    Unfortunately this doesn't seem to work. This problem also appears when I make a new project.
    Maybe deleting and re-installing Unity could solve this problem?

    B.t.w. in the console the following message appears:

    ArgumentException: Value does not fall within the expected range.
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.LanguageOf (SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit unit)
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits (System.String method)
    SyntaxTree.VisualStudio.Unity.Bridge.CompilationUnit.CompilationUnits ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder..ctor ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectSystem.UnitySolutionBuilder.CreateSolutionFromAssetDatabase ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilesGenerator.GenerateProject ()
    SyntaxTree.VisualStudio.Unity.Bridge.ProjectFilePostprocessor.OnPreGeneratingCSProjectFiles ()
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles () (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:91)
    UnityEditor.VisualStudioIntegration.SolutionSynchronizer.Sync () (at C:/buildslave/unity/build/Editor/Mono/VisualStudioIntegration/SolutionSynchronizer.cs:196)
    UnityEditor.SyncVS.SyncSolution () (at C:/buildslave/unity/build/Editor/Mono/SyncProject.cs:190)
     
  4. Louis_Amerongen

    Louis_Amerongen

    Joined:
    Jul 21, 2017
    Posts:
    19
    Today I tried to re-install Unity. Unfortunately without good result.

    It looks like .sln files aren't made when I make a C# script.
    When I kopie sln files from a previous version, Visual Studio still doesn't recognize the Unity Code (for example public GameObject Test; (GameObject is not recognized )).

    I also tried to test with a new Project Folder.

    Help!!!

    Thanks in advance Louis
     
  5. Louis_Amerongen

    Louis_Amerongen

    Joined:
    Jul 21, 2017
    Posts:
    19
    I solved the problem.
    The solution was to re-install Visual Studio.
     
    Shippety likes this.
  6. mjunaidch

    mjunaidch

    Joined:
    Oct 23, 2016
    Posts:
    7
    Anybody have solution of this problem rather then reinstall Visual Studio ??? I have unity 2018.1.6f1 with Visual studio 2013. Visual Studio works good with Unity 2017.

    I install Visual Studio Community 2017 then it works
     
    Last edited: Jul 11, 2018
  7. Rosencrantz

    Rosencrantz

    Joined:
    Jan 12, 2013
    Posts:
    1
    I was having this problem with Unity 2018.2.1f1, but updating Visual Studio Community 2017 to version 15.7.5 fixed it for me (I believe I was at 15.5.X before).
     
  8. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hey guys, I found out something easy to fix it (without having to update Visual Studio all the time). In the Unity Editor, you can go to Edit->Preferences. Click on the "External Tools" tab. Then in "External Script Editor" dropdown option select "Browse" and browse your Windows folders for Notepad (I had to find the Notepad.exe on Windows first then I could navigate to it). Once you have Notepad selected as your External Script Editor, open one of your scripts (it should open with Notepad). Close it, and now switch back the External Script Editor to using your version of Visual Studio you are using. Unity should now find your .sln solution file again.

    I hope that might help, and I hope the Visual Studio team can keep this fixed, it really shouldn't keep breaking with every version of Unity or Visual Studio being released......it is VERY annoying. Thank you.
     
  9. pr0t0type94

    pr0t0type94

    Joined:
    Jan 23, 2018
    Posts:
    1
    Awesome bro! This problem got me all day crazy till i found your post. I dont know why this happens but definetly they should take a look on it.
     
  10. SkorpionX

    SkorpionX

    Joined:
    Jul 11, 2016
    Posts:
    3
    Worked for me too, thanks a lot!
     
  11. tfishell

    tfishell

    Joined:
    Nov 20, 2017
    Posts:
    97
    By George I think this worked for me too. Thanks!
     
  12. dpgdemos

    dpgdemos

    Joined:
    Apr 28, 2014
    Posts:
    24
    Worked for me as well in Unity 2018.2.14.f1 and VS Pro 2017.
    Many many thanks!!
     
  13. rajeshrdas

    rajeshrdas

    Joined:
    Dec 14, 2018
    Posts:
    1

    Thank You, It worked
     
  14. ktmarine1999

    ktmarine1999

    Joined:
    Jan 30, 2014
    Posts:
    11
    This worked for me as well, had this issue after upgrading from Unity 2018.2.something to Unity 2018.3.0f2 on my laptop. Was getting the error with a project that I upgraded. So I tried with a new Unity project and got the same error. Updated my visual studio and that did not work. The notepad trick worked great. Guess that Unity isn't creating the .sln and file correctly out of the box for some reason. Only had to do this once, afterwards when going to a different project, the ones that weren't working before, worked.
     
  15. TrollAxeThrower

    TrollAxeThrower

    Joined:
    Dec 24, 2012
    Posts:
    16
    Thanks man. Works like a charm.
     
  16. yang_xiong

    yang_xiong

    Joined:
    Aug 15, 2018
    Posts:
    1
    worked for me !Thanks!
     
  17. bluetenu

    bluetenu

    Joined:
    Dec 6, 2014
    Posts:
    5
    Still an issue, and Velo222's solution still works!
     
  18. tomhog

    tomhog

    Joined:
    Dec 22, 2012
    Posts:
    36
    Velo222's solution worked for me too. Many thanks.

    If it helps the unity devs, I ran Unity 2019 (clean install), didn't install visual studio along side it as already had 2013, 2015 and 2017 installed (community versions).

    When I first went to change the script editor 2017 wasn't listed. I added that first so did change the setting (it had selected 2015). Still didn't work though. Switching to notepad++ and back to VS 2107 worked.
     
  19. MonkDeniz

    MonkDeniz

    Joined:
    Nov 1, 2018
    Posts:
    5
    We found another thing that causes the same issue. If your path contains "^", you get the same error and updating or switching editors does not help. Just delete/replace the "^" characters and it should be fine.
     
  20. Ghady983

    Ghady983

    Joined:
    Oct 4, 2018
    Posts:
    2
    Guys , for the ones who still have that error, well there is a solution. the problem is that VS needs a .sln file for the project while VS should create one but it couldn't . Whatever, you need to create That Format using VS Code, It Is small and for free. Just Change the script editor in preferences to vs code and open at least 1 script with vs code and change back to VS(The original). Now You're asking why can't VS create Sln, it may be because you accidentally changed something in the settings or somewhere else. That's why Louis's solution worked because When he re-installs it, Everything goes back to default
     
  21. MaZy

    MaZy

    Joined:
    Jun 29, 2012
    Posts:
    107
    Suddently I have this problem aswell. I don't know.. from one moment to another I get on ALL projects with unity "incompatible" problem. I am not sure what is happening. The solutions above did NOT help.

    The only help is to uninstall Unity Tools from Visual Studio and it is suddently generating again c# projects. I am not sure why this suddendly... I don't get it....
     
    Last edited: Oct 30, 2019
  22. jayawantk

    jayawantk

    Joined:
    Nov 15, 2018
    Posts:
    1
    This solution worked for me
    thanks
     
  23. Karlhali

    Karlhali

    Joined:
    Mar 29, 2020
    Posts:
    1
    Very easy and nice solution. Thanks. I was just recovering from a BSoD festival my PC suffered and was in no mood imaginable to reinstall the visual studio again. :D
     
  24. mahmoudennami

    mahmoudennami

    Joined:
    Jul 5, 2020
    Posts:
    1

    Thanks, that for me as well
     
  25. novastrangers

    novastrangers

    Joined:
    Sep 16, 2013
    Posts:
    5
    If none of above solutions don't work deleting all VS files from the project root might help.
    By all files I mean all .sln, .csproj files, and VERY IMPORTANT also delete folders .vs (hidden), obj, temp.
     
    Last edited: Aug 28, 2021
  26. BabasahebPawar

    BabasahebPawar

    Joined:
    Apr 9, 2019
    Posts:
    1
    Great solution...
     
  27. davie_unity

    davie_unity

    Joined:
    Mar 1, 2024
    Posts:
    2
    I came here from the "Boat Attack" project in GitHub. The reason I was unable to get Visual Studio 2022 Community to build a .sln for that project was that the JetBrains Rider package was pushed in the repo.
    After removing that and adding the Visual Studio package via Package Manager, the "Regenerate Project Files" button reappeared.
     
  28. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Please don't necro threads.
     
Thread Status:
Not open for further replies.