Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CSHARP-5707: Use standard RID paths in MongoDB.Driver.Encryption packaging #1782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adelinowona wants to merge 2 commits into mongodb:main
base: main
Choose a base branch
Loading
from adelinowona:csharp5705

Conversation

Copy link
Contributor

@adelinowona adelinowona commented Sep 30, 2025

  • Local testing: Verified that when an application consuming the encryption package is published for a specific platform, the correct native library is automatically copied to the publish output directory
  • Cross-platform validation: Used Docker containers to test applications on different target platforms, confirming they can successfully locate and load the appropriate native libraries
  • Ensured no NETSDK1152 errors occur during builds targeting specific Runtime Identifiers (RIDs)

@adelinowona adelinowona requested a review from a team as a code owner September 30, 2025 04:00
@adelinowona adelinowona requested review from ajcvickers, BorisDog and sanych-sun and removed request for a team and ajcvickers September 30, 2025 04:00

<Target Name="DownloadNativeBinaries_Alpine" BeforeTargets="BeforeBuild" Condition="!Exists('$(MSBuildProjectDirectory)/runtimes/linux/native/alpine/libmongocrypt.so')">

<Target Name="DownloadNativeBinaries_AlpineAMD64" BeforeTargets="BeforeBuild" Condition="!Exists('$(MSBuildProjectDirectory)/runtimes/linux-musl-x64/native/libmongocrypt.so')">
Copy link
Contributor Author

@adelinowona adelinowona Sep 30, 2025
edited
Loading

Choose a reason for hiding this comment

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

Added explicit linux-musl-x64 RID mapping to ensure correct native library selection

During local testing, I discovered that MSBuild's RID fallback mechanism was causing incorrect library resolution. According to the RID compatibility graph, linux-musl-x64 is compatible with linux-x64, which caused MSBuild to use the linux-x64 native library as a fallback for linux-musl-x64 targets.

Since we provide a dedicated native library built specifically for linux-musl-x64, this change ensures that the platform-specific library is selected instead of relying on the fallback mechanism.

sanych-sun reacted with thumbs up emoji
<Content Include="$(MSBuildProjectDirectory)/runtimes/linux/native/arm64/libmongocrypt.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Content Include="$(MSBuildProjectDirectory)/runtimes/linux-musl-arm64/native/libmongocrypt.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Copy link
Contributor Author

@adelinowona adelinowona Sep 30, 2025
edited
Loading

Choose a reason for hiding this comment

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

Switched to PreserveNewest as it follows MSBuild best practices by only copying files when they've been modified, rather than copying on every build. While this should theoretically improve build performance, the impact will be negligible given our small number of native libraries. Made the change for consistency with recommended practices.

<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>runtimes\osx\native</PackagePath>
Copy link
Contributor Author

@adelinowona adelinowona Sep 30, 2025

Choose a reason for hiding this comment

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

The macOS paths remain unchanged because our packaged library is a universal binary that supports both arm64 and x64 architectures. According to MSBuild's RID compatibility fallback graph, both osx-x64 and osx-arm64 fall back to osx, so the current structure already handles both platforms correctly without requiring separate RID-specific paths.

Comment on lines 1 to 8
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="$([MSBuild]::IsOsPlatform('Windows'))">
<Content Include="$(MSBuildThisFileDirectory)../runtimes/win/native/mongocrypt.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ItemGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true' AND $([MSBuild]::IsOsPlatform('Windows'))">
<Content Include="$(MSBuildThisFileDirectory)../runtimes/win-x64/native/mongocrypt.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>mongocrypt.dll</Link>
</Content>
</ItemGroup>
Copy link
Contributor Author

@adelinowona adelinowona Sep 30, 2025
edited
Loading

Choose a reason for hiding this comment

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

From my understanding this target file provides backward compatibility for older, non-SDK-style projects (e.g., .NET Framework with packages.config) that do not automatically handle native assets from the 'runtimes' folder.

The condition ensures this logic ONLY runs for non-SDK-style projects. Modern .NET SDK projects (which set 'UsingMicrosoftNETSdk' to 'true') will handle native asset copying automatically based on the RID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@BorisDog BorisDog Awaiting requested review from BorisDog

@sanych-sun sanych-sun Awaiting requested review from sanych-sun

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /