Skip to content

Conversation

ViveliDuCh
Copy link
Member

@ViveliDuCh ViveliDuCh commented Sep 17, 2025

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 generated AppHost/Program.cs references normalized class names (e.g., some_name instead of some.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

…-aspire projects. Add execution tests for the fix.
@ViveliDuCh ViveliDuCh requested a review from a team as a code owner September 17, 2025 23:01
@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 23:01
@github-actions github-actions bot added the area-ai-templates Microsoft.Extensions.AI.Templates label Sep 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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.

@ViveliDuCh ViveliDuCh added the area-ai Microsoft.Extensions.AI libraries label Sep 17, 2025
@jeffhandley jeffhandley removed the area-ai Microsoft.Extensions.AI libraries label Sep 18, 2025
@ViveliDuCh ViveliDuCh requested a review from jozkee September 19, 2025 00:14
@ViveliDuCh ViveliDuCh requested a review from jozkee September 22, 2025 20:48
jeffhandley and others added 2 commits September 22, 2025 17:53
…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.
Copy link
Member

@MackinnonBuck MackinnonBuck left a 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!

Copy link
Member

@jeffhandley jeffhandley left a 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!

@ViveliDuCh ViveliDuCh merged commit 7200baa into dotnet:main Sep 24, 2025
6 checks passed
@ViveliDuCh ViveliDuCh deleted the bugfix-6331 branch September 24, 2025 16:00
This was referenced Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai-templates Microsoft.Extensions.AI.Templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MEAI chat web template with --aspire flag: Class name mismatch in AppHost Program.cs causes build error

4 participants