Skip to content

Omit connection string placeholders when running EF tool during publish#17905

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-connection-strings-publish
Open

Omit connection string placeholders when running EF tool during publish#17905
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-connection-strings-publish

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 4, 2026

Fixes #17847

Description

During aspire publish, the EF Core tool generates migration scripts/bundles by running the migration's startup project. The ConnectionStrings__<name> env var (from WithReference) 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 to dotnet ef, causing design-time DbContext creation 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 new GetToolEnvironmentVariables helper that skips ConnectionStringReference values when in publish mode. Run mode is unchanged (real values still flow through).
  • Tests: added unit tests covering placeholder omission in publish mode and preservation of real connection strings in run mode.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Copilot AI and others added 2 commits June 4, 2026 15:33
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…ublish

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17905

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17905"

Copy link
Copy Markdown
Contributor

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 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 skips ConnectionStringReference values in publish mode.
  • Add unit tests validating omission in publish mode and preservation in run mode.
  • Add a minimal IExecutionConfigurationResult test 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).

@AndriySvyryd AndriySvyryd marked this pull request as ready for review June 4, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postgres with PublishAsMigrationBundle fails to publish

3 participants