Skip to content

Commit

Permalink
Fix native libs selection in System.IO.Ports package (dotnet#106231)
Browse files Browse the repository at this point in the history
The runtime.native.System.IO.Ports package depends on all the RID-specific packages, this causes an issue when publishing for a RID like `linux-musl-x64` since
the RID graph has a fallback path of `linux-musl-x64 -> linux-x64 -> linux` so the SDK would select the native libs from _both_ the `runtime.linux-musl-x64.runtime.native.System.IO.Ports` and `runtime.linux-x64.runtime.native.System.IO.Ports` packages which causes a conflict.

To fix this we add `_._` placeholder entries for all RIDs except the one where we have a native asset so the SDK ignores the non-matching ones.

Fixes dotnet#104710
  • Loading branch information
akoeplinger authored Aug 12, 2024
1 parent 6169e41 commit 8d51dc9
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,30 @@
<PackageReadmeFilePath>$(MSBuildThisFileDirectory)../src/PACKAGE.md</PackageReadmeFilePath>
</PropertyGroup>

<ItemGroup>
<!-- Extract supported RIDs from the .proj file names -->
<RIDSpecificProject Include="$(MSBuildThisFileDirectory)runtime.*.runtime.native.System.IO.Ports.proj" />
<PackageSupportedRID Include="@(RIDSpecificProject->'%(Filename)'->Replace('.runtime.native.System.IO.Ports', '')->Replace('runtime.', ''))" />

<!-- We need to add a placeholder file for all RIDs except the one that is actually included in the RID-specific package.
This prevents an issue where during publish the SDK would select e.g. both linux-x64 and linux-musl-x64 assets because of the fallback path in the RID graph. -->
<PackagePlaceholderRID Include="@(PackageSupportedRID)" Exclude="$(OutputRID)" />
</ItemGroup>

<ItemGroup>
<None Include="$(NativeBinDir)$(LibPrefix)System.IO.Ports.Native$(LibSuffix)"
PackagePath="runtimes/$(OutputRID)/native"
Pack="true" />
<None Include="$(PlaceholderFile)"
PackagePath="@(PackagePlaceholderRID->'runtimes/%(Identity)/native')"
Pack="true" />
</ItemGroup>

<Target Name="ValidatePackageSupportedRID" BeforeTargets="Build">
<Error Text="$(OutputRID) is missing from PackageSupportedRID."
Condition="!@(PackageSupportedRID->AnyHaveMetadataValue('Identity', '$(OutputRID)'))" />
</Target>

<Target Name="AddRuntimeSpecificNativeSymbolToPackage">
<ItemGroup>
<TfmSpecificDebugSymbolsFile Include="$(NativeBinDir)$(LibPrefix)System.IO.Ports.Native$(LibSuffix)$(SymbolsSuffix)"
Expand Down

0 comments on commit 8d51dc9

Please sign in to comment.