88using System . Linq ;
99using System . Reflection ;
1010using System . Text ;
11+ using System . Xml ;
12+ using System . Xml . Linq ;
1113using JetBrains . Annotations ;
1214using Nuke . Common ;
1315using Nuke . Common . Execution ;
@@ -27,7 +29,7 @@ partial class Program
2729{
2830 // ReSharper disable InconsistentNaming
2931
30- private const string TARGET_FRAMEWORK = "net8 .0" ;
32+ private const string TARGET_FRAMEWORK = "net10 .0" ;
3133 private const string PROJECT_KIND = "9A19103F-16F7-4668-BE54-9A1E7A4F7556" ;
3234
3335 // ReSharper disable once CognitiveComplexity
@@ -84,7 +86,7 @@ public static int Setup(string[] args, [CanBeNull] AbsolutePath rootDirectory, [
8486 "Which solution should be the default?" ,
8587 choices : new DirectoryInfo ( rootDirectory )
8688 . EnumerateFiles ( "*" , SearchOption . AllDirectories )
87- . Where ( x => x . FullName . EndsWithOrdinalIgnoreCase ( ".sln" ) )
89+ . Where ( x => x . FullName . EndsWithOrdinalIgnoreCase ( ".sln" ) || x . FullName . EndsWithOrdinalIgnoreCase ( ".slnx" ) )
8890 . OrderByDescending ( x => x . FullName )
8991 . Select ( x => ( x , rootDirectory . GetRelativePathTo ( x . FullName ) . ToString ( ) ) )
9092 . Concat ( ( null , "None" ) ) . ToArray ( ) ) ? . FullName ;
@@ -110,10 +112,22 @@ public static int Setup(string[] args, [CanBeNull] AbsolutePath rootDirectory, [
110112
111113 if ( solutionFile != null )
112114 {
113- var solutionFileContent = solutionFile . ReadAllLines ( ) . ToList ( ) ;
114115 var buildProjectFileRelative = solutionFile . Parent . GetWinRelativePathTo ( buildProjectFile ) ;
115- UpdateSolutionFileContent ( solutionFileContent , buildProjectFileRelative , buildProjectGuid , buildProjectName ) ;
116- solutionFile . WriteAllLines ( solutionFileContent , Encoding . UTF8 ) ;
116+ if ( solutionFile . Extension . EqualsOrdinalIgnoreCase ( ".slnx" ) )
117+ {
118+ var solutionDocument = XDocument . Load ( solutionFile ) ;
119+ UpdateSolutionXmlFileContent ( solutionDocument , buildProjectFileRelative ) ;
120+
121+ var settings = new XmlWriterSettings { OmitXmlDeclaration = true , Indent = true } ;
122+ using var writer = XmlWriter . Create ( solutionFile , settings ) ;
123+ solutionDocument . Save ( writer ) ;
124+ }
125+ else
126+ {
127+ var solutionFileContent = solutionFile . ReadAllLines ( ) . ToList ( ) ;
128+ UpdateSolutionFileContent ( solutionFileContent , buildProjectFileRelative , buildProjectGuid , buildProjectName ) ;
129+ solutionFile . WriteAllLines ( solutionFileContent , Encoding . UTF8 ) ;
130+ }
117131 }
118132
119133 buildProjectFile . WriteAllLines (
@@ -186,12 +200,27 @@ internal static void UpdateSolutionFileContent(
186200 "EndProject" ) ;
187201 }
188202
203+ internal static void UpdateSolutionXmlFileContent ( XDocument content , string buildProjectFileRelative )
204+ {
205+ var solutionElement = content . Root ;
206+ Assert . True ( solutionElement ? . Name == "Solution" , "Could not find a root 'Solution' element in solution file" ) ;
207+
208+ // file uses forward slashes for paths on every platform
209+ var path = buildProjectFileRelative . Replace ( oldChar : '\\ ' , newChar : '/' ) ;
210+
211+ if ( solutionElement . Elements ( "Project" ) . Any ( x => x . GetAttributeValue ( "Path" ) . EqualsOrdinalIgnoreCase ( path ) ) )
212+ {
213+ return ;
214+ }
215+
216+ solutionElement . Add ( new XElement ( "Project" , new XAttribute ( "Path" , path ) ) ) ;
217+ }
218+
189219 private static string [ ] GetTemplate ( string templateName )
190220 {
191221 return ResourceUtility . GetResourceAllLines < Program > ( $ "templates.{ templateName } ") ;
192222 }
193223
194-
195224 private static void WriteBuildScripts (
196225 AbsolutePath scriptDirectory ,
197226 AbsolutePath rootDirectory ,
0 commit comments