Search Unity

Bug Creation of Visual Studio project files by script fails (Unity 2021.3.7, Visual Studio Build Tools)

Discussion in 'Code Editors & IDEs' started by H0RST, Aug 29, 2022.

  1. H0RST

    H0RST

    Joined:
    Jan 27, 2017
    Posts:
    3
    We generate the Visual Studio 2019 project files via a C# script. After installation of the Unity LTS version 2021.3.7 the project files are not created. We tried the following two proposals:

    Code (CSharp):
    1.  
    2. // use reflection
    3. Assembly unityEditorAssembly = Assembly.GetAssembly(typeof(ActiveEditorTracker));
    4. Type syncVsType = unityEditorAssembly.GetType("UnityEditor.SyncVS");
    5. MethodInfo syncSolution = syncVsType.GetMethod("SyncSolution");
    6. syncSolution.Invoke(null, new object[0]);
    7.  
    Code (CSharp):
    1.  
    2. // direct call
    3. Unity.CodeEditor.CodeEditor.Editor.CurrentCodeEditor.SyncAll();
    4.  
    After that we switched to the Rider package. With this call the project files are created.

    Code (CSharp):
    1.  
    2. // use the Rider package
    3. Packages.Rider.Editor.RiderScriptEditor.SyncSolution();
    4.  
    When the Visual Studio 2019 IDE is installed, everything is as expected. The value of CodeEditor.CurrentEditor is set to 'Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor'. The created solution contains entries for the Debug and Release configuration.

    Code (CSharp):
    1.  
    2. Microsoft Visual Studio Solution File, Format Version 12.00
    3. # Visual Studio 15
    4. Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{146DC92F-68A6-764D-5386-1A2691CB68E1}"
    5. EndProject
    6. Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{0E303456-8278-5AA7-DD10-D036E70D0DF4}"
    7. EndProject
    8. Global
    9.     GlobalSection(SolutionConfigurationPlatforms) = preSolution
    10.         Debug|Any CPU = Debug|Any CPU
    11.         Release|Any CPU = Release|Any CPU
    12.     EndGlobalSection
    13.     GlobalSection(ProjectConfigurationPlatforms) = postSolution
    14.         {146DC92F-68A6-764D-5386-1A2691CB68E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    15.         {146DC92F-68A6-764D-5386-1A2691CB68E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
    16.         {146DC92F-68A6-764D-5386-1A2691CB68E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
    17.         {146DC92F-68A6-764D-5386-1A2691CB68E1}.Release|Any CPU.Build.0 = Release|Any CPU
    18.         {0E303456-8278-5AA7-DD10-D036E70D0DF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    19.         {0E303456-8278-5AA7-DD10-D036E70D0DF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
    20.         {0E303456-8278-5AA7-DD10-D036E70D0DF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
    21.         {0E303456-8278-5AA7-DD10-D036E70D0DF4}.Release|Any CPU.Build.0 = Release|Any CPU
    22.     EndGlobalSection
    23.     GlobalSection(SolutionProperties) = preSolution
    24.         HideSolutionNode = FALSE
    25.     EndGlobalSection
    26. EndGlobal
    27.  
    But, on our build machine the Visual Studio 2019 IDE is not installed, but the Visual Studio 2019 Build Tools. Now the value of CodeEditor.CurrentEditor is set to 'UnityEditor.DefaultExternalCodeEditor' and the created .sln file doesn't contain an entry for the Release configuration. We need that for the static code analysis with Resharper.

    Code (CSharp):
    1.  
    2. Microsoft Visual Studio Solution File, Format Version 11.00
    3. # Visual Studio 2010
    4. Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{2fc96d14-a668-4d76-5386-1a2691cb68e1}"
    5. EndProject
    6. Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{5634300e-7882-a75a-dd10-d036e70d0df4}"
    7. EndProject
    8. Global
    9.     GlobalSection(SolutionConfigurationPlatforms) = preSolution
    10.         Debug|Any CPU = Debug|Any CPU
    11.     EndGlobalSection
    12.     GlobalSection(ProjectConfigurationPlatforms) = postSolution
    13.         {2fc96d14-a668-4d76-5386-1a2691cb68e1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    14.         {2fc96d14-a668-4d76-5386-1a2691cb68e1}.Debug|Any CPU.Build.0 = Debug|Any CPU
    15.         {5634300e-7882-a75a-dd10-d036e70d0df4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    16.         {5634300e-7882-a75a-dd10-d036e70d0df4}.Debug|Any CPU.Build.0 = Debug|Any CPU
    17.     EndGlobalSection
    18.     GlobalSection(SolutionProperties) = preSolution
    19.         HideSolutionNode = FALSE
    20.     EndGlobalSection
    21. EndGlobal
    22.  
    I'm also confused about the different versions of Visual Studio listed in the first two lines of the generated solution file.

    Any idea what went wrong here? Thanks for any answer.
     
  2. van800

    van800

    JetBrains Employee

    Joined:
    May 19, 2016
    Posts:
    73
  3. H0RST

    H0RST

    Joined:
    Jan 27, 2017
    Posts:
    3
    Thanks for your answer. We are not using Rider as External Script Editor in Unity.

    What do you mean with "use just dotnet instead"? Resharper requires the .sln files as input for the SCA.