Skip to content

Add directory path support to AddProject method #10516

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 18, 2025

This PR adds support for directory paths to the AddProject(string name, string projectPath) method, allowing users to specify a directory containing a .csproj file instead of requiring the full path to the project file.

Changes

  • Enhanced AddProject method: Now accepts both file paths and directory paths
  • Auto-discovery logic: When a directory path is provided, automatically searches for .csproj files
  • Error handling: Provides clear error messages for edge cases (multiple files, no files found)
  • Backward compatibility: Existing file path usage continues to work unchanged
  • Comprehensive tests: Added tests covering all directory scenarios
  • Updated documentation: Added examples showing both file and directory path usage

Usage Examples

Before (still supported):

builder.AddProject("app", "../PathToCode.Folder/PathToCode.Folder.csproj");

After (new functionality):

builder.AddProject("app", "../PathToCode.Folder");

This matches the behavior of AddNpmApp and AddPythonApp which also accept directory paths:

builder.AddNpmApp("app", "../pathToCode");
builder.AddPythonApp("app", "../pathToCode", "main.py");

Implementation Details

  • If the path is a directory, searches for *.csproj files
  • If exactly one .csproj file is found, uses it automatically
  • If multiple .csproj files are found, throws DistributedApplicationException with file names listed
  • If no .csproj files are found, throws DistributedApplicationException with clear message
  • File paths continue to work exactly as before (100% backward compatible)

Testing

  • All existing tests pass
  • New tests cover:
    • Directory with single .csproj file ✅
    • Directory with multiple .csproj files (error case) ✅
    • Directory with no .csproj files (error case) ✅
    • File paths still work as before ✅
  • Manual testing confirms all scenarios work correctly

Fixes #10439.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 18, 2025 00:32
Co-authored-by: maddymontaquila <12660687+maddymontaquila@users.noreply.github.com>
Co-authored-by: maddymontaquila <12660687+maddymontaquila@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] builder.AddProject(name, projectPath) overload Add directory path support to AddProject method Jul 18, 2025
@Copilot Copilot AI requested a review from maddymontaquila July 18, 2025 00:34
Copilot finished work on behalf of maddymontaquila July 18, 2025 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

builder.AddProject(name, projectPath) overload
2 participants