@@ -20,6 +20,7 @@ internal class SolutionAddCommand : CommandBase
20
20
private readonly IReadOnlyCollection < string > _projects ;
21
21
private readonly string ? _solutionFolderPath ;
22
22
private string _solutionFileFullPath = string . Empty ;
23
+ private bool _addReferencedProjects ;
23
24
24
25
private static string GetSolutionFolderPathWithForwardSlashes ( string path )
25
26
{
@@ -41,6 +42,7 @@ public SolutionAddCommand(ParseResult parseResult) : base(parseResult)
41
42
_projects = ( IReadOnlyCollection < string > ) ( parseResult . GetValue ( SolutionAddCommandParser . ProjectPathArgument ) ?? [ ] ) ;
42
43
_inRoot = parseResult . GetValue ( SolutionAddCommandParser . InRootOption ) ;
43
44
_solutionFolderPath = parseResult . GetValue ( SolutionAddCommandParser . SolutionFolderOption ) ;
45
+ _addReferencedProjects = parseResult . GetValue ( SolutionAddCommandParser . AddReferencedProjectsOption ) ;
44
46
SolutionArgumentValidator . ParseAndValidateArguments ( _fileOrDirectory , _projects , SolutionArgumentValidator . CommandType . Add , _inRoot , _solutionFolderPath ) ;
45
47
_solutionFileFullPath = SlnFileFactory . GetSolutionFileFullPath ( _fileOrDirectory ) ;
46
48
}
@@ -202,6 +204,21 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio
202
204
project . AddProjectConfigurationRule ( new ConfigurationRule ( BuildDimension . BuildType , solutionBuildType , "*" , projectBuildType ) ) ;
203
205
}
204
206
207
+ // Get referencedprojects from the project instance
208
+ var referencedProjectsFullPaths = projectInstance . EvaluatedItemElements
209
+ . Where ( item => item . ItemType == "ProjectReference" )
210
+ . Select ( item => item . Include )
211
+ . Select ( item => Path . GetFullPath ( item , Path . GetDirectoryName ( fullProjectPath ) ) )
212
+ . ToList ( ) ;
213
+
205
214
Reporter . Output . WriteLine ( CliStrings . ProjectAddedToTheSolution , solutionRelativeProjectPath ) ;
215
+
216
+ if ( _addReferencedProjects )
217
+ {
218
+ foreach ( var referencedProjectFullPath in referencedProjectsFullPaths )
219
+ {
220
+ AddProject ( solution , referencedProjectFullPath , serializer ) ;
221
+ }
222
+ }
206
223
}
207
224
}
0 commit comments