@@ -586,6 +586,11 @@ public string ProjectFile(Assembly assembly)
586586#endif
587587
588588 public string SolutionFile ( )
589+ {
590+ return SolutionFileImpl ( ) ;
591+ }
592+
593+ internal virtual string SolutionFileImpl ( )
589594 {
590595 return Path . Combine ( ProjectDirectory . NormalizePathSeparators ( ) , $ "{ InvalidCharactersRegexPattern . Replace ( m_ProjectName , "_" ) } .sln") ;
591596 }
@@ -821,6 +826,26 @@ internal virtual void GetProjectFooter(StringBuilder footerBuilder)
821826 {
822827 }
823828
829+ private static string GetSolutionText ( )
830+ {
831+ return string . Join ( k_WindowsNewline ,
832+ @"" ,
833+ @"Microsoft Visual Studio Solution File, Format Version {0}" ,
834+ @"# Visual Studio {1}" ,
835+ @"{2}" ,
836+ @"Global" ,
837+ @" GlobalSection(SolutionConfigurationPlatforms) = preSolution" ,
838+ @" Debug|Any CPU = Debug|Any CPU" ,
839+ @" Release|Any CPU = Release|Any CPU" ,
840+ @" EndGlobalSection" ,
841+ @" GlobalSection(ProjectConfigurationPlatforms) = postSolution" ,
842+ @"{3}" ,
843+ @" EndGlobalSection" ,
844+ @"{4}" ,
845+ @"EndGlobal" ,
846+ @"" ) . Replace ( " " , "\t " ) ;
847+ }
848+
824849 private void SyncSolution ( IEnumerable < Assembly > assemblies )
825850 {
826851 if ( InvalidCharactersRegexPattern . IsMatch ( ProjectDirectory ) )
@@ -831,16 +856,29 @@ private void SyncSolution(IEnumerable<Assembly> assemblies)
831856 SyncSolutionFileIfNotChanged ( solutionFile , SolutionText ( assemblies , previousSolution ) ) ;
832857 }
833858
834- private string SolutionText ( IEnumerable < Assembly > assemblies , Solution previousSolution = null )
859+ internal virtual string SolutionText ( IEnumerable < Assembly > assemblies , Solution previousSolution = null )
835860 {
836861 const string fileversion = "12.00" ;
837862 const string vsversion = "15" ;
838863
864+ var projects = GetSolutionProjects ( assemblies , previousSolution ) ;
865+ var properties = previousSolution != null ? previousSolution . Properties : null ;
866+
867+ string propertiesText = GetPropertiesText ( properties ) ;
868+ string projectEntriesText = GetProjectEntriesText ( projects ) ;
869+
870+ // do not generate configurations for SolutionFolders
871+ var configurableProjects = projects . Where ( p => ! p . IsSolutionFolderProjectFactory ( ) ) ;
872+ string projectConfigurationsText = string . Join ( k_WindowsNewline , configurableProjects . Select ( p => GetProjectActiveConfigurations ( p . ProjectGuid ) ) . ToArray ( ) ) ;
873+
874+ return string . Format ( GetSolutionText ( ) , fileversion , vsversion , projectEntriesText , projectConfigurationsText , propertiesText ) ;
875+ }
876+
877+ internal List < SolutionProjectEntry > GetSolutionProjects ( IEnumerable < Assembly > assemblies , Solution previousSolution = null )
878+ {
839879 var relevantAssemblies = RelevantAssembliesForMode ( assemblies ) ;
840880 var generatedProjects = ToProjectEntries ( relevantAssemblies ) . ToList ( ) ;
841881
842- SolutionProperties [ ] properties = null ;
843-
844882 // First, add all projects generated by Unity to the solution
845883 var projects = new List < SolutionProjectEntry > ( ) ;
846884 projects . AddRange ( generatedProjects ) ;
@@ -853,34 +891,9 @@ private string SolutionText(IEnumerable<Assembly> assemblies, Solution previousS
853891 . Where ( p => generatedProjects . All ( gp => gp . FileName != p . FileName ) ) ;
854892
855893 projects . AddRange ( externalProjects ) ;
856- properties = previousSolution . Properties ;
857894 }
858895
859- string propertiesText = GetPropertiesText ( properties ) ;
860- string projectEntriesText = GetProjectEntriesText ( projects ) ;
861-
862- // do not generate configurations for SolutionFolders
863- var configurableProjects = projects . Where ( p => ! p . IsSolutionFolderProjectFactory ( ) ) ;
864- string projectConfigurationsText = string . Join ( k_WindowsNewline , configurableProjects . Select ( p => GetProjectActiveConfigurations ( p . ProjectGuid ) ) . ToArray ( ) ) ;
865-
866- const string solutionText =
867- "" + k_WindowsNewline
868- + "Microsoft Visual Studio Solution File, Format Version {0}" + k_WindowsNewline
869- + "# Visual Studio {1}" + k_WindowsNewline
870- + "{2}" + k_WindowsNewline
871- + "Global" + k_WindowsNewline
872- + "\t GlobalSection(SolutionConfigurationPlatforms) = preSolution" + k_WindowsNewline
873- + "\t \t Debug|Any CPU = Debug|Any CPU" + k_WindowsNewline
874- + "\t \t Release|Any CPU = Release|Any CPU" + k_WindowsNewline
875- + "\t EndGlobalSection" + k_WindowsNewline
876- + "\t GlobalSection(ProjectConfigurationPlatforms) = postSolution" + k_WindowsNewline
877- + "{3}" + k_WindowsNewline
878- + "\t EndGlobalSection" + k_WindowsNewline
879- + "{4}" + k_WindowsNewline
880- + "EndGlobal" + k_WindowsNewline
881- + "" ;
882-
883- return string . Format ( solutionText , fileversion , vsversion , projectEntriesText , projectConfigurationsText , propertiesText ) ;
896+ return projects ;
884897 }
885898
886899 private static IEnumerable < Assembly > RelevantAssembliesForMode ( IEnumerable < Assembly > assemblies )
@@ -942,6 +955,7 @@ private string GetProjectEntriesText(IEnumerable<SolutionProjectEntry> entries)
942955 private IEnumerable < SolutionProjectEntry > ToProjectEntries ( IEnumerable < Assembly > assemblies )
943956 {
944957 foreach ( var assembly in assemblies )
958+ {
945959 yield return new SolutionProjectEntry ( )
946960 {
947961 ProjectFactoryGuid = SolutionGuid ( assembly ) ,
@@ -950,6 +964,7 @@ private IEnumerable<SolutionProjectEntry> ToProjectEntries(IEnumerable<Assembly>
950964 ProjectGuid = ProjectGuid ( assembly ) ,
951965 Metadata = k_WindowsNewline
952966 } ;
967+ }
953968 }
954969
955970 /// <summary>
0 commit comments