I have odd problem with my Unity project, sometimes Visual Studio gives error “This unity project was not generated for the Visual Studio Tools for Unity. …” and it can’t connect to unity or find other classes.
I took closer look what is wrong and noticed that when problem occurs .sln file headers are
# Visual Studio 2010```
And when that happens I have to go unity preferences and click "Regenerate project files". then those header lines will be
```Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
and everything works again.
Project has com.unity.ide.visualstudio@2.0.14 and com.unity.ide.vscode@1.2.5 installed.
on both packages /Editor/ProjectGeneration/ProjectGeneration.cs has GetSolutionText() method that seems to generate .sln file content and vscode generates that wrong one. Also .csproj files are different, but I don’t have took closer look to those at all.
On unity Preferences > External Tools > External Script Editor I have selected Visual Studio Community 2019
Why it still sometimes generates project files for vscode?
Next I will remove vscode package and hope it will fix this, but this still looks line a bug on unity side.
This may help you with intellisense and possibly other Visual Studio integration problems:
Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.
Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.
Barring all that, move on to other ideas:
Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button
It happens again, this time I didn’t even had vscode plugin installed anymore.
.vsconfig doesn’t have any changes at all.
I tried Assets → Open C# Project from Unity solution and it fixes it for a while, but bit later same problem is there again.
Also, I noticed it happens every time on my current project when I double click error message on console while game is running, it’s not happening when game is stopped or clicking file/line number on stacktrace section.
How do I nuke the userprefs?
What/where are those crufty low-value high-hassle files so I can keep those in eye?
AFAIK actual Visual Studio project definition are those .sln and .csproj files on Unity project root and Unity generates those.
Those will (generally) all be placed at the same level as Assets and ProjectSettings.
Lately Visual Studio also makes a .vsconfig file and/or a .vs folder which has other irrelevant information that likes to become corrupt and lead it astray.
.vsconfig content doesn’t have changed at all. I check with Process Monitor that it is Unity that rewrites those project files.
Also on Editor.log has following lines every time when corruption happens
[C# Project] Writing E:/Projects/BugTestProject\BugTestProject.sln because it has changed
[C# Project] First difference on line 2
[C# Project] Current E:/Projects/BugTestProject\BugTestProject.sln:
[C# Project] 002: Microsoft Visual Studio Solution File, Format Version 12.00
[C# Project] 003: # Visual Studio 15
[C# Project] 004: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{1095F0C7-C73C-B148-DBF2-CFB491BE18C0}"
[C# Project] 005: EndProject
[C# Project] 006: Global
[C# Project] New E:/Projects/BugTestProject\BugTestProject.sln:
[C# Project] 002: Microsoft Visual Studio Solution File, Format Version 11.00
[C# Project] 003: # Visual Studio 2010
[C# Project] 004: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{1095F0C7-C73C-B148-DBF2-CFB491BE18C0}"
[C# Project] 005: EndProject
[C# Project] 006: Global
and similar for every .csproj file on project
But those lines that starts with [C# Project] doesn’t be there when regenerating project files with “Regenerate project files” button or “Open C# Project”
I tried to create new project with attached files, it corrupts those project files every time.
We had this issue and after 4 days testing all the possible solutions we found on the internet we tracked down the problem being that the project’s file path had the character “%20”, after renaming the folder to a name with only letters and numbers both Visual Studio Community and Rider started working properly.