-
Notifications
You must be signed in to change notification settings - Fork 722
Add AddAzureFunctionsProject overload accepting project path #12658
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
base: main
Are you sure you want to change the base?
Conversation
- Implemented new AddAzureFunctionsProject(name, projectPath) overload - Refactored existing implementation to share code via AddAzureFunctionsProjectCore helper method - Added AzureFunctionsProjectMetadata class to handle path-based project metadata - Added helper method NormalizePathForCurrentPlatform for path normalization - Added comprehensive tests for the new overload including path normalization, environment variables, and storage configuration Co-authored-by: captainsafia <[email protected]>
- Support all project types (*.*proj) not just C# projects (.csproj) - Clarify comment about project file discovery to cover both zero and multiple file cases Co-authored-by: captainsafia <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12658Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12658" |
|
@copilot We need to fix this error. Update the RootNamespace the RESX is against.
|
The LaunchProfileStrings.resx embedded resource was using the wrong namespace. The Designer.cs expects "Aspire.Hosting.Resources.LaunchProfileStrings.resources" but it was getting "Aspire.Hosting.Azure.Functions.Resources.LaunchProfileStrings.resources". Fixed by adding LogicalName attribute to the EmbeddedResource element to explicitly set the correct resource name. Co-authored-by: captainsafia <[email protected]>
Fixed in commit 188890f. Added |
|
@copilot Update the tests that validate the new projectPath-based overload to create a project file in a temporary directory to work around the project file not found exceptions.
Copilot, are you an F# fanboy? 😆 |
Updated all path-based AddAzureFunctionsProject tests to create actual .csproj files in temporary directories instead of using non-existent file paths. This prevents "project file not found" exceptions during test execution. Each test now: - Creates a temp directory using Path.GetTempPath() - Writes a minimal project file - Uses the real file path for testing - Cleans up the temp directory in a finally block Co-authored-by: captainsafia <[email protected]>
Updated in commit 4f57efc. All path-based tests now create real .csproj files in temporary directories and clean them up properly to prevent "project file not found" exceptions. P.S. Just keeping the examples multi-language friendly! 😄 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Fix the test failure related to incomplete mocked data from the Bicep call. [+965/x1/?0] Aspire.Hosting.Azure.Tests.dll (net8.0|arm64) - Aspire.Hosting.Azure.Tests.AzureDeployerTests.DeployAsync_WithAzureFunctionsProject_Works (1m 10s) fail: Aspire.Hosting.Publishing.PipelineExecutor[0] |
Added the missing 'id' output for the funcapp-containerapp deployment in the DeployAsync_WithAzureFunctionsProject_Works test. This output is required when an Azure Functions project is deployed to a container app environment, as the Bicep provisioner needs this id to reference the deployed container app resource. Co-authored-by: captainsafia <[email protected]>
Fixed in commit 93eaff4. Added the missing |
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 adds a new overload to AddAzureFunctionsProject that accepts a project file path as a string parameter, enabling Azure Functions projects to be added to the application model without requiring a compile-time project reference. The implementation mirrors the existing AddProject API design patterns.
Key changes:
- New
AddAzureFunctionsProject(string name, string projectPath)overload with path normalization - Refactored core logic into
AddAzureFunctionsProjectCoreto reduce code duplication - Added
AzureFunctionsProjectMetadataclass to handle project path resolution
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs | Adds new public API overload accepting project path, refactors shared logic into core method, implements path normalization and project metadata handling |
| src/Aspire.Hosting.Azure.Functions/Aspire.Hosting.Azure.Functions.csproj | Adds LogicalName to embedded resource for proper runtime resolution |
| tests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs | Adds 6 comprehensive tests covering the new overload's functionality including path normalization, environment configuration, storage sharing, and annotation behavior; includes whitespace cleanup |
| tests/Aspire.Hosting.Azure.Tests/AzureDeployerTests.cs | Updates mock deployment output handler to support container app resources with proper precedence ordering |
| using var builder = TestDistributedApplicationBuilder.Create(); | ||
|
|
||
| // Create a temporary project file | ||
| var tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); |
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.
@copilot look for the TempDirectory helper used in other tests and use it here too.
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.
Updated in commit 9dcdfdc. Replaced manual temp directory creation and cleanup with the TempDirectory helper, which provides automatic cleanup via IDisposable and is consistent with other tests in the suite.
Replaced manual temporary directory creation and cleanup with the TempDirectory helper class that's used throughout the test suite. This provides: - Automatic cleanup via IDisposable pattern - Consistent temp directory handling - Simpler, more maintainable test code - Better error handling during cleanup Co-authored-by: davidfowl <[email protected]>
Summary
This PR successfully implements a new
AddAzureFunctionsProjectoverload that accepts a project path as a string parameter, addressing the issue where users cannot add Azure Functions projects dynamically or reference projects outside their solution.Problem Statement
Previously,
AddAzureFunctionsProjectonly supported a generic type parameter approach:This required:
Users needed dynamic path-based project addition similar to the existing
AddProject(name, path)method.Solution
Added a new overload that accepts a project path:
Implementation Details
Code Changes
New Public API:
AddAzureFunctionsProject(name, projectPath).csproj,.fsproj,.vbproj)Refactored Shared Logic:
AddAzureFunctionsProjectCore(private)Helper Components:
AzureFunctionsProjectMetadata: ImplementsIProjectMetadatafor path-based projectsNormalizePathForCurrentPlatform: Handles path normalizationResolveProjectPath: Auto-discovers project files in directoriesResource Fix: Fixed embedded resource naming
LogicalNameattribute toLaunchProfileStrings.resxembeddingTest Updates:
TempDirectoryhelper for consistent temp file handlingFiles Modified
src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs- Added new overload and refactoredsrc/Aspire.Hosting.Azure.Functions/Aspire.Hosting.Azure.Functions.csproj- Fixed RESX resource namingtests/Aspire.Hosting.Azure.Tests/AzureFunctionsTests.cs- Added comprehensive tests using TempDirectory helpertests/Aspire.Hosting.Azure.Tests/AzureDeployerTests.cs- Fixed mock data for deployment testTest Coverage
Added 6 new tests (all using
TempDirectoryhelper):AddAzureFunctionsProject_WithProjectPath_Works- Basic functionalityAddAzureFunctionsProject_WithProjectPath_NormalizesPath- Path normalizationAddAzureFunctionsProject_WithProjectPath_ConfiguresEnvironmentVariables- Environment setupAddAzureFunctionsProject_WithProjectPath_SharesDefaultStorage- Storage sharingAddAzureFunctionsProject_WithProjectPath_CanUseCustomHostStorage- Custom storage (Docker)AddAzureFunctionsProject_WithProjectPath_AddsAzureFunctionsAnnotation- Annotation verificationFixed existing test:
DeployAsync_WithAzureFunctionsProject_Works- Fixed mock deployment outputsUsage Examples
Basic Usage
With Dynamic Paths
Multi-language Support
Backward Compatibility
Key Features
✅ Backward Compatible - Existing code continues to work unchanged
✅ Maximum Code Reuse - Shared implementation via helper method
✅ Consistent API - Follows
AddProjectpattern✅ Path Flexibility - Absolute or relative paths
✅ Directory Support - Auto-discovers project files
✅ Multi-language - C#, F#, VB.NET support
✅ Well Documented - XML docs with examples
✅ Thoroughly Tested - Comprehensive test coverage using standard helpers
✅ Code Reviewed - All feedback addressed
✅ Security Checked - CodeQL analysis passed
✅ Resource Fix - Fixed embedded resource naming issue
✅ Test Fixes - Fixed deployment test mock data and refactored to use TempDirectory helper
Validation
Related
Fixes #12641
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.