Skip to content

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Dec 14, 2024

Npgsql supports net8.0 and net9.0, which means we can just update to the latest version and don't need to multi-target or split dependencies.

Fix #6720
Fix #6852

Microsoft Reviewers: Open in CodeFlow

@eerhardt
Copy link
Member Author

eerhardt commented Jan 3, 2025

I needed to update the Npgsql EF library so it continued using Npgsql 8 when using EF 8. See npgsql/npgsql#5987

Npgsql supports net8.0 and net9.0, which means we can just update to the latest version and don't need to multi-target or split dependencies.

Fix dotnet#6720
…previous code was creating them in the static initializer.
…is requires updating the app to target net9.0.
public static BuildEnvironment ForDefaultFramework { get; } = DefaultTargetFramework switch
{
TestTargetFramework.Previous => ForPreviousSdkOnly,
public static BuildEnvironment ForDefaultFramework =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - @radical.

The current code evaluates these Lazy properties in the static initializer. I refactored this so it is only touched when this property is touched.

Comment on lines +23 to +24
Since this project uses both Npgsql and Npgsql.EntityFrameworkCore, we need to ensure they are both the same major version.
Aspire.Npgsql uses Npgsql v9, so we need to use Npgsql.EntityFrameworkCore v9 (and target net9.0 as well) to match.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This situation is getting a little messy. The major versions of Npgsql and Npgsql.EntityFrameworkCore need to match, or else you run into breaking changes like: #6852 (comment).

With this change, we only target Npgsql v9, no matter the TFM you target. So this needs to use EF Core 9, which is only supported with aspire if you target net9.0. So that's what I made this test do.

FYI @joperezr @sebastienros @roji

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense - as I wrote in npgsql/npgsql#5987 (comment), EFCore.PG 9.0 requires Npgsql 9.0 because of some changes in how enums are managed; but in general, the EF provider and Npgsql sometimes need to interoperate tightly, resulting in major version dependencies. So this is expected - I hope this is OK on your side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is OK. We just need to ensure we match the major versions (and so will any customers).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW EFCore.PG does specify upper nuget versions for EF itself, since they're also tightly coupled; with Npgsql/EFCore.PG I haven't done that so far... Will consider it for the next release if we have known major breaks.

Comment on lines +26 to +33
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" VersionOverride="9.0.0" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to send out a separate PR which refactors our Directory.Packages.props so this is no longer necessary.

@eerhardt eerhardt merged commit aed9d43 into dotnet:main Jan 7, 2025
9 checks passed
@eerhardt eerhardt deleted the UpdateNpgsql9 branch January 7, 2025 23:19
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2025
@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AddKeyedNpgsqlDataSource fails on Aspire 9: MissingMethodException Update Npgsql dependency to 9.0
3 participants