Skip to content

Commit 8d51dc9

Browse files
authored
Fix native libs selection in System.IO.Ports package (#106231)
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 #104710
1 parent 6169e41 commit 8d51dc9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libraries/System.IO.Ports/pkg/runtime.native.System.IO.Ports.props

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,30 @@
1717
<PackageReadmeFilePath>$(MSBuildThisFileDirectory)../src/PACKAGE.md</PackageReadmeFilePath>
1818
</PropertyGroup>
1919

20+
<ItemGroup>
21+
<!-- Extract supported RIDs from the .proj file names -->
22+
<RIDSpecificProject Include="$(MSBuildThisFileDirectory)runtime.*.runtime.native.System.IO.Ports.proj" />
23+
<PackageSupportedRID Include="@(RIDSpecificProject->'%(Filename)'->Replace('.runtime.native.System.IO.Ports', '')->Replace('runtime.', ''))" />
24+
25+
<!-- We need to add a placeholder file for all RIDs except the one that is actually included in the RID-specific package.
26+
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. -->
27+
<PackagePlaceholderRID Include="@(PackageSupportedRID)" Exclude="$(OutputRID)" />
28+
</ItemGroup>
29+
2030
<ItemGroup>
2131
<None Include="$(NativeBinDir)$(LibPrefix)System.IO.Ports.Native$(LibSuffix)"
2232
PackagePath="runtimes/$(OutputRID)/native"
2333
Pack="true" />
34+
<None Include="$(PlaceholderFile)"
35+
PackagePath="@(PackagePlaceholderRID->'runtimes/%(Identity)/native')"
36+
Pack="true" />
2437
</ItemGroup>
2538

39+
<Target Name="ValidatePackageSupportedRID" BeforeTargets="Build">
40+
<Error Text="$(OutputRID) is missing from PackageSupportedRID."
41+
Condition="!@(PackageSupportedRID->AnyHaveMetadataValue('Identity', '$(OutputRID)'))" />
42+
</Target>
43+
2644
<Target Name="AddRuntimeSpecificNativeSymbolToPackage">
2745
<ItemGroup>
2846
<TfmSpecificDebugSymbolsFile Include="$(NativeBinDir)$(LibPrefix)System.IO.Ports.Native$(LibSuffix)$(SymbolsSuffix)"

0 commit comments

Comments
 (0)