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.
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.
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)
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 )).
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
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).
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.
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.
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.
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.
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