-
Notifications
You must be signed in to change notification settings - Fork 839
Add project name normalization to match aspire's code generator logic #6818
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
…-aspire projects. Add execution tests for the fix.
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 addresses build errors that occur when using the --aspire
flag with project names containing dots or other non-identifier characters. The fix applies Aspire's project name normalization logic to templates to ensure generated code references match the normalized class names.
- Adds project name normalization transforms to template configuration
- Introduces a new test case to verify the fix works with project names containing dots
- Ensures consistency between template-generated code and Aspire's AppHost target behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
AIChatWebExecutionTests.cs | Adds test case for project names with dots to verify normalization fix |
template.json | Implements project name normalization transforms using regex replacement |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Outdated
Show resolved
Hide resolved
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Outdated
Show resolved
Hide resolved
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Outdated
Show resolved
Hide resolved
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Outdated
Show resolved
Hide resolved
… flag. More test cases coverage.
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Outdated
Show resolved
Hide resolved
…ests. Make the Aspire project name theory conditional.
Add an [EnvironmentVariableSkipCondition] attribute for conditional tests. Make the Aspire project name theory conditional. Keep a single [Fact] that gives comprehensive coverage of the pattern for a single provider.
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 one piece of feedback but looks great!
...ates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/.template.config/template.json
Outdated
Show resolved
Hide resolved
...ojectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs
Show resolved
Hide resolved
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.
Good idea removing _Web
from the replacement token so that it doesn't have to be re-appended.
Since this is now a single-step regex replacement, I had look back at the https://github.com/dotnet/templating/wiki/Reference-for-template.json#derived-symbol docs to understand why this is a derived
replacer vs. the same generator
approach as is used in the Aspire template. It makes sense though--we need the project name to get plugged in and do post-processing over that derived symbol.
Looks good!
Fixes #6811
Apply project name transformation in the templates' generated code using the same normalization logic as in
Aspire.Hosting.AppHost.targets
. This ensures that when the--aspire
flag is used, the generatedAppHost/Program.cs
references normalized class names (e.g.,some_name
instead ofsome.name
), resolving build errors caused by mismatched type or namespace references.Add execution tests to verify the fix for templates with dots or other non-identifier characters in their names.
Microsoft Reviewers: Open in CodeFlow