Search Unity

Bug Incorrect visual studio project generation, Unity 2020.3.29f1

Discussion in 'Editor & General Support' started by Thasan, Mar 4, 2022.

  1. Thasan

    Thasan

    Joined:
    Feb 22, 2018
    Posts:
    7
    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

    Microsoft Visual Studio Solution File, Format Version 11.00
    # 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.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    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:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874
     
  3. Thasan

    Thasan

    Joined:
    Feb 22, 2018
    Posts:
    7
    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.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    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.
     
  5. Thasan

    Thasan

    Joined:
    Feb 22, 2018
    Posts:
    7
    .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
    Code (CSharp):
    1. [C# Project] Writing E:/Projects/BugTestProject\BugTestProject.sln because it has changed
    2. [C# Project] First difference on line 2
    3.  
    4. [C# Project] Current E:/Projects/BugTestProject\BugTestProject.sln:
    5. [C# Project]   002: Microsoft Visual Studio Solution File, Format Version 12.00
    6. [C# Project]   003: # Visual Studio 15
    7. [C# Project]   004: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{1095F0C7-C73C-B148-DBF2-CFB491BE18C0}"
    8. [C# Project]   005: EndProject
    9. [C# Project]   006: Global
    10.  
    11. [C# Project] New E:/Projects/BugTestProject\BugTestProject.sln:
    12. [C# Project]   002: Microsoft Visual Studio Solution File, Format Version 11.00
    13. [C# Project]   003: # Visual Studio 2010
    14. [C# Project]   004: Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{1095F0C7-C73C-B148-DBF2-CFB491BE18C0}"
    15. [C# Project]   005: EndProject
    16. [C# Project]   006: Global
    17.  
    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.
     

    Attached Files:

  6. Houtamelo

    Houtamelo

    Joined:
    Jan 3, 2020
    Posts:
    31
    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.