Omit connection string placeholders when running EF tool during publish#17905
Open
Copilot wants to merge 2 commits into
Open
Omit connection string placeholders when running EF tool during publish#17905Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…ublish Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
AndriySvyryd
June 4, 2026 15:42
View session
Closed
14 tasks
Contributor
|
🚀 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" |
Contributor
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?