Omit connection string placeholders when running EF tool during publish - #17905
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…ublish Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17905Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17905" |
There was a problem hiding this comment.
Pull request overview
This PR adjusts how the EF Core tool process is launched during aspire publish so that connection string environment variables coming from WithReference are not forwarded when they resolve to manifest placeholders (e.g., {postgresdb.connectionString}), avoiding EF design-time DbContext creation failures. This aligns with the publish-time behavior where the actual connection string is only available at deploy time, while still preserving current run-mode behavior.
Changes:
- Route EF tool environment-variable application through a new helper (
GetToolEnvironmentVariables) that skipsConnectionStringReferencevalues in publish mode. - Add unit tests validating omission in publish mode and preservation in run mode.
- Add a minimal
IExecutionConfigurationResulttest stub to exercise the environment-variable selection logic without launching a process.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs | Filters EF tool environment variables in publish mode to avoid passing connection string placeholders. |
| tests/Aspire.Hosting.EntityFrameworkCore.Tests/EFMigrationPipelineTests.cs | Adds unit coverage for the new environment-variable filtering behavior (publish vs run). |
PR Testing ReportPR Information
CLI Version Verification
Changes AnalyzedFiles Changed
Change Categories
Test Scenarios ExecutedScenario 1: Publish EF-migrations AppHost (happy path / core fix)Objective: Run Setup:
Result:
Artifacts produced:
Scenario 2: Run-mode contrast (boundary)Objective: Verify the fix only suppresses connection strings in publish mode and still forwards them in run mode. Expected Unhappy-Path Outcome: In publish mode, a Summary
Overall Result✅ PR VERIFIED The PR resolves the publish-time failure: Recommendations
|
Mitch Denny (mitchdenny)
left a comment
There was a problem hiding this comment.
Reviewed the publish-mode connection string filtering and focused tests. No actionable issues found. Follow-up E2E deployment coverage has been filed separately.
|
✅ No documentation update needed. docs_optional → false positive signal Triggered signal (1): The PR is a bug fix that corrects |
Fixes #17847
Description
During
aspire publish, the EF Core tool generates migration scripts/bundles by running the migration's startup project. TheConnectionStrings__<name>env var (fromWithReference) resolves to a manifest placeholder expression (e.g.{postgresdb.connectionString}) in publish mode, since the target database isn't provisioned yet. That placeholder was passed todotnet ef, causing design-timeDbContextcreation to fail with "Format of the initialization string does not conform to specification starting at index 0."Generating a migration script/bundle doesn't need a live connection — the bundle receives the real connection string at deploy time (invoked with
--connection "$ConnectionStrings__<name>").Changes
EFResourceBuilderExtensions.StartEfToolResourceAsync: route the EF tool's environment variables through a newGetToolEnvironmentVariableshelper that skipsConnectionStringReferencevalues when in publish mode. Run mode is unchanged (real values still flow through).Checklist
<remarks />and<code />elements on your triple slash comments?