-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sln-add: --include-references when adding a project #48815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
471d3f2
69a479a
38c7840
993c28c
bd001ce
09abcb9
1576ff5
34c0d37
266ef2e
f8e64fe
c0b6c3b
4b810a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ internal class SolutionAddCommand : CommandBase | |
private readonly IReadOnlyCollection<string> _projects; | ||
private readonly string? _solutionFolderPath; | ||
private string _solutionFileFullPath = string.Empty; | ||
private bool _includeReferences; | ||
|
||
private static string GetSolutionFolderPathWithForwardSlashes(string path) | ||
{ | ||
|
@@ -43,6 +44,7 @@ public SolutionAddCommand(ParseResult parseResult) : base(parseResult) | |
_projects = (IReadOnlyCollection<string>)(parseResult.GetValue(SolutionAddCommandParser.ProjectPathArgument) ?? []); | ||
_inRoot = parseResult.GetValue(SolutionAddCommandParser.InRootOption); | ||
_solutionFolderPath = parseResult.GetValue(SolutionAddCommandParser.SolutionFolderOption); | ||
_includeReferences = parseResult.GetValue(SolutionAddCommandParser.IncludeReferencesOption); | ||
SolutionArgumentValidator.ParseAndValidateArguments(_fileOrDirectory, _projects, SolutionArgumentValidator.CommandType.Add, _inRoot, _solutionFolderPath); | ||
_solutionFileFullPath = SlnFileFactory.GetSolutionFileFullPath(_fileOrDirectory); | ||
} | ||
|
@@ -138,7 +140,7 @@ private async Task AddProjectsToSolutionAsync(IEnumerable<string> projectPaths, | |
await serializer.SaveAsync(_solutionFileFullPath, solution, cancellationToken); | ||
} | ||
|
||
private void AddProject(SolutionModel solution, string fullProjectPath, ISolutionSerializer serializer = null) | ||
private void AddProject(SolutionModel solution, string fullProjectPath, ISolutionSerializer serializer = null, bool showMessageOnDuplicate = true) | ||
{ | ||
string solutionRelativeProjectPath = Path.GetRelativePath(Path.GetDirectoryName(_solutionFileFullPath), fullProjectPath); | ||
|
||
|
@@ -175,7 +177,10 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio | |
} | ||
catch (SolutionArgumentException ex) when (ex.Type == SolutionErrorType.DuplicateProjectName || solution.FindProject(solutionRelativeProjectPath) is not null) | ||
{ | ||
Reporter.Output.WriteLine(CliStrings.SolutionAlreadyContainsProject, _solutionFileFullPath, solutionRelativeProjectPath); | ||
if (showMessageOnDuplicate) | ||
{ | ||
Reporter.Output.WriteLine(CliStrings.SolutionAlreadyContainsProject, _solutionFileFullPath, solutionRelativeProjectPath); | ||
} | ||
return; | ||
} | ||
|
||
|
@@ -205,5 +210,17 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio | |
} | ||
|
||
Reporter.Output.WriteLine(CliStrings.ProjectAddedToTheSolution, solutionRelativeProjectPath); | ||
|
||
// Get referencedprojects from the project instance | ||
var referencedProjectsFullPaths = projectInstance.GetItems("ProjectReference") | ||
.Select(item => Path.GetFullPath(item.EvaluatedInclude, Path.GetDirectoryName(fullProjectPath))); | ||
|
||
if (_includeReferences) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding cycle detection or duplicate addition checks when recursively adding referenced projects to prevent potential infinite recursion in cases of cyclic project references. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
foreach (var referencedProjectFullPath in referencedProjectsFullPaths) | ||
{ | ||
AddProject(solution, referencedProjectFullPath, serializer, showMessageOnDuplicate: false); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net10.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\B\B.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<Solution> | ||
</Solution> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net10.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to ReferencedProjects is clear to you but probably opaque to most people
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Recursively add project references to the solution"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "Set to false to disable recursively adding all ProjectReferences"? My initial thought was that ReferencedProjects is an internal implementation detail, but looking now, it'd also be nice to include that the default is 'true'.