-
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
Conversation
563179c
to
2f429ad
Compare
Update option name
2f429ad
to
471d3f2
Compare
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.
Pull Request Overview
This PR introduces a new command option (--include-references) to enable adding referenced projects along with a project in a solution.
- Added IncludeReferencesOption to the command parser with a default value of true
- Modified the command implementation to extract and recursively add project references when the flag is enabled
Reviewed Changes
Copilot reviewed 3 out of 21 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommandParser.cs | Added a new option for including referenced projects |
src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs | Captured the new flag in the command and extended AddProject to add referenced projects conditionally |
Files not reviewed (18)
- src/Cli/dotnet/Commands/CliCommandStrings.resx: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf: Language not supported
- src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf: Language not supported
- test/TestAssets/TestProjects/SlnFileWithReferencedProjects/A/A.csproj: Language not supported
- test/TestAssets/TestProjects/SlnFileWithReferencedProjects/App.sln: Language not supported
- test/TestAssets/TestProjects/SlnFileWithReferencedProjects/App.slnx: Language not supported
- test/TestAssets/TestProjects/SlnFileWithReferencedProjects/B/B.csproj: Language not supported
@@ -202,6 +204,21 @@ private void AddProject(SolutionModel solution, string fullProjectPath, ISolutio | |||
project.AddProjectConfigurationRule(new ConfigurationRule(BuildDimension.BuildType, solutionBuildType, "*", projectBuildType)); | |||
} | |||
|
|||
// Get referencedprojects from the project instance |
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.
[nitpick] Consider updating the comment to 'Get referenced projects from the project instance' for improved clarity.
// Get referencedprojects from the project instance | |
// Get referenced projects from the project instance |
Copilot uses AI. Check for mistakes.
Reporter.Output.WriteLine(CliStrings.ProjectAddedToTheSolution, solutionRelativeProjectPath); | ||
|
||
if (_includeReferences) |
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.
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.
@@ -2483,4 +2483,7 @@ To display a value, specify the corresponding command-line option without provid | |||
<data name="ZeroTestsRan" xml:space="preserve"> | |||
<value>Zero tests ran</value> | |||
</data> | |||
</root> | |||
<data name="SolutionAddReferencedProjectsOptionDescription" xml:space="preserve"> | |||
<value>Recursively add projects' ReferencedProjects to solution</value> |
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'.
var referencedProjectsFullPaths = projectInstance.EvaluatedItemElements | ||
.Where(item => item.ItemType == "ProjectReference") | ||
.Select(item => item.Include) | ||
.Select(item => Path.GetFullPath(item, Path.GetDirectoryName(fullProjectPath))) |
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.
You don't need to pay attention to Exclude/Remove?
Currently looking exclude/remove handling and skipping already-added projects (per copilot's comment) |
The current behavior for adding existing projects is to just print a message saying it's been added already. It doesn't fail and in this case I think it should absolutely not fail (i.e., as a user I wouldn't expect it to fail if I'm being a good citizen and doing things "correctly" -- adding all needed projects). However, we could make the output message conditional. I would love to also hear @baronfel 's opinion here. I will look into how to handle the exclude/remove and see if |
I agree that it absolutely should not fail; I just hadn't realized it was covered properly. Looks like it is, but it's halfway down the method, so I missed it. Perhaps check earlier so we can skip some extra work? I also would prefer that it not print a message when it's a recursive call, as that would add confusion when users see things that weren't added that they'd never intended to add or that they'd already added. Like: |
I like the idea of not adding the message if in a recursive call, and how it can be very confusing to users. I will also check for a good way of identifying this beforehand to avoid unnecessary steps |
Just noticed this kindof addresses #28781 |
As per offline discussion, by the time you're enumerating individual items with projectInstance.GetItems("ProjectReference") all include/exclude/remove operations are done |
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.
Pull Request Overview
This pull request adds the --include-references option when adding a project to a solution. The key changes include new project files and solution files for test assets, updated resource strings for localized messages, and modifications to the solution add command parser and implementation to recursively add referenced projects.
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
test/TestAssets/TestProjects/SlnFileWithReferencedProjects/* | New test projects and solution files to support referenced projects |
src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommandParser.cs | Added a new option for including referenced projects |
src/Cli/dotnet/Commands/Solution/Add/SolutionAddCommand.cs | Updated command implementation to process the new option and recursively add project references |
src/Cli/dotnet/Commands/xlf/*, CliCommandStrings.resx | Added localized strings for the new option |
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.
Just the one tweak for when vs. if, and I think I'm happy 🙂 Thanks for working through this!
No description provided.