@@ -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
}
@@ -195,6 +197,21 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio
195
197
project . AddProjectConfigurationRule ( new ConfigurationRule ( BuildDimension . BuildType , solutionBuildType , "*" , projectBuildType ) ) ;
196
198
}
197
199
200
+ // Get referencedprojects from the project instance
201
+ var referencedProjectsFullPaths = projectInstance . EvaluatedItemElements
202
+ . Where ( item => item . ItemType == "ProjectReference" )
203
+ . Select ( item => item . Include )
204
+ . Select ( item => Path . GetFullPath ( item , Path . GetDirectoryName ( fullProjectPath ) ) )
205
+ . ToList ( ) ;
206
+
198
207
Reporter . Output . WriteLine ( CliStrings . ProjectAddedToTheSolution , solutionRelativeProjectPath ) ;
208
+
209
+ if ( _addReferencedProjects )
210
+ {
211
+ foreach ( var referencedProjectFullPath in referencedProjectsFullPaths )
212
+ {
213
+ AddProject ( solution , referencedProjectFullPath , serializer ) ;
214
+ }
215
+ }
199
216
}
200
217
}
0 commit comments