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:
// use reflection
Assembly unityEditorAssembly = Assembly.GetAssembly(typeof(ActiveEditorTracker));
Type syncVsType = unityEditorAssembly.GetType("UnityEditor.SyncVS");
MethodInfo syncSolution = syncVsType.GetMethod("SyncSolution");
syncSolution.Invoke(null, new object[0]);
// direct call
Unity.CodeEditor.CodeEditor.Editor.CurrentCodeEditor.SyncAll();
After that we switched to the Rider package. With this call the project files are created.
// use the Rider package
Packages.Rider.Editor.RiderScriptEditor.SyncSolution();
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.
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{146DC92F-68A6-764D-5386-1A2691CB68E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{0E303456-8278-5AA7-DD10-D036E70D0DF4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{146DC92F-68A6-764D-5386-1A2691CB68E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{146DC92F-68A6-764D-5386-1A2691CB68E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{146DC92F-68A6-764D-5386-1A2691CB68E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{146DC92F-68A6-764D-5386-1A2691CB68E1}.Release|Any CPU.Build.0 = Release|Any CPU
{0E303456-8278-5AA7-DD10-D036E70D0DF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E303456-8278-5AA7-DD10-D036E70D0DF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E303456-8278-5AA7-DD10-D036E70D0DF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E303456-8278-5AA7-DD10-D036E70D0DF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
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.
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{2fc96d14-a668-4d76-5386-1a2691cb68e1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{5634300e-7882-a75a-dd10-d036e70d0df4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2fc96d14-a668-4d76-5386-1a2691cb68e1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2fc96d14-a668-4d76-5386-1a2691cb68e1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5634300e-7882-a75a-dd10-d036e70d0df4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5634300e-7882-a75a-dd10-d036e70d0df4}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
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.