Skip to content

dotnet publish -r linux-x64 resolves reference assembly instead of runtime assembly for net10.0 apps #4461

Description

@mahdiyar021

Describe the bug

When publishing a .NET 10 application with -r linux-x64 that references Microsoft.Data.SqlClient (transitively via Microsoft.EntityFrameworkCore.SqlServer), the publish output places the reference assembly from lib/net9.0/ at the output root instead of the Unix runtime assembly from runtimes/unix/lib/net9.0/. At runtime, the reference assembly throws PlatformNotSupportedException.

To Reproduce

  1. Create a .NET 10 app with a transitive dependency on Microsoft.Data.SqlClient 7.0.1 (e.g. via Microsoft.EntityFrameworkCore.SqlServer)
  2. Publish with RID:
    dotnet publish -c Release -r linux-x64 -o ./publish
  3. Run on Linux (Ubuntu 24.04, amd64):
    dotnet ./publish/App.dll
  4. Any attempt to create a SqlConnection throws:
    System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.

Expected behavior

The Unix runtime assembly (runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll, ~1.8 MB) should be placed at the publish root, not the reference assembly (lib/net9.0/Microsoft.Data.SqlClient.dll, ~632 KB).

Evidence

  • dotnet run (no publish, no RID) works correctly — the runtime resolves the Unix DLL dynamically
  • The .deps.json correctly references runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll
  • Both DLLs are present in the publish output, but the root one (632K) gets loaded instead of the unix one (1.8M)
  • The package only has net9.0 TFMs; the app targets net10.0 (TFM fallback gap may contribute)

Environment

  • Microsoft.Data.SqlClient: 7.0.1
  • .NET SDK: 10.0.302 (container: mcr.microsoft.com/dotnet/sdk:10.0)
  • .NET Runtime: 10.0.10
  • OS: Ubuntu 24.04.4 LTS, linux-x64
  • Publish command: dotnet publish -c Release -r linux-x64 -o ./publish

Workaround

An MSBuild target that copies the Unix runtime DLL over the reference assembly after publish:

<Target Name="FixSqlClientRuntimeAssembly" AfterTargets="Publish"
     Condition="$([System.String]::new('$(RuntimeIdentifier)').StartsWith('linux'))">
  <PropertyGroup>
 <SqlClientUnixRuntime>$(PublishDir)runtimes/unix/lib/net9.0/Microsoft.Data.SqlClient.dll</SqlClientUnixRuntime>
 <SqlClientRoot>$(PublishDir)Microsoft.Data.SqlClient.dll</SqlClientRoot>
  </PropertyGroup>
  <Copy SourceFiles="$(SqlClientUnixRuntime)" DestinationFiles="$(SqlClientRoot)"
     Condition="Exists('$(SqlClientUnixRuntime)')" />
</Target>

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status
Waiting for customer

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions