Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c95f049

Browse files
committed
Move reference expansion to a target and handle simple name conflicts
We cannot let simple name references that overlap with our assemblies reach RAR because RAR will choose the files in the targeting pack over the ones we add to the reference item, due to the default AssemblySearchPaths. We could change AssemblySearchPaths to consider all the NuGetPackage paths before `{TargetFrameworkDirectory}` but that has broader implications for compatibility and performance of RAR. I chose to follow a similar pattern to what the SDK does already and took the opportunity to move the reference item setting into the target as well, to more closely match what the SDK is doing.
1 parent a6ae889 commit c95f049

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

pkg/NETStandard.Library.NETFramework/NETStandard.Library.NETFramework.pkgproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<File Include="targets\**\*.*" Exclude="@(StampFile)">
2727
<TargetPath>build/%(RecursiveDir)</TargetPath>
2828
</File>
29+
<File Include="$(PlaceHolderFile)">
30+
<TargetPath>build/net471</TargetPath>
31+
</File>
2932
</ItemGroup>
3033

3134
<ItemGroup>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Choose>
3+
<!-- Allow completely disabling the conflict resolution targets-->
4+
<When Condition="'$(ImplicitlyExpandNETStandardFacades)' != 'true'" />
5+
<!-- Condition here is a hack until https://github.com/dotnet/sdk/issues/534 is fixed -->
6+
<When Condition="'$(TargetFramework)' != '' or '$(TargetFrameworks)' != ''">
7+
<!-- NuGet 4, run after references are resolved -->
8+
<PropertyGroup>
9+
<ImplicitlyExpandNETStandardFacadesAfter>ResolveLockFileReferences</ImplicitlyExpandNETStandardFacadesAfter>
10+
</PropertyGroup>
11+
</When>
12+
<When Condition="'$(ResolveNuGetPackages)' == 'true' and Exists('$(ProjectLockFile)')">
13+
<!-- NuGet 3, run after nuget assets are resolved -->
14+
<PropertyGroup>
15+
<ImplicitlyExpandNETStandardFacadesAfter>ResolveNuGetPackageAssets</ImplicitlyExpandNETStandardFacadesAfter>
16+
</PropertyGroup>
17+
</When>
18+
<Otherwise>
19+
<!-- NuGet 2, run before targets that consume references -->
20+
<PropertyGroup>
21+
<ResolveAssemblyReferencesDependsOn>ImplicitlyExpandNETStandardFacades;$(ResolveAssemblyReferencesDependsOn)</ResolveAssemblyReferencesDependsOn>
22+
<PrepareResourcesDependsOn>ImplicitlyExpandNETStandardFacades;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
23+
</PropertyGroup>
24+
</Otherwise>
25+
</Choose>
26+
27+
<PropertyGroup>
28+
<!-- Ensure this runs before conflict resolution since the added files may cause conflicts -->
29+
<HandlePackageFileConflictsDependsOn>ImplicitlyExpandNETStandardFacades;$(HandlePackageFileConflictsDependsOn)</HandlePackageFileConflictsDependsOn>
30+
</PropertyGroup>
31+
32+
<Target Name="ImplicitlyExpandNETStandardFacades"
33+
AfterTargets="$(ImplicitlyExpandNETStandardFacadesAfter)">
34+
<ItemGroup>
35+
<!-- Remove simple name references if we're directly providing a reference assembly to the compiler. For example,
36+
consider a project with an Reference Include="System", and some NuGet package is providing System.dll.
37+
Simple references can also come from NuGet framework assemblies, hence this statement should occur after
38+
including all computed references. -->
39+
<Reference Remove="%(_NETStandardLibraryNETFrameworkReference.FileName)" />
40+
41+
<Reference Include="@(_NETStandardLibraryNETFrameworkReference)">
42+
<!-- Private = false to make these reference only -->
43+
<Private>false</Private>
44+
<NuGetPackageId>NETStandard.Library.NETFramework</NuGetPackageId>
45+
<NuGetPackageVersion>$(NETStandardLibraryNETFrameworkPackageVersion)</NuGetPackageVersion>
46+
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
47+
<NuGetSourceType>Package</NuGetSourceType>
48+
</Reference>
49+
50+
<ReferenceCopyLocalPaths Include="@(_NETStandardLibraryNETFrameworkLib)">
51+
<Private>false</Private>
52+
<NuGetPackageId>NETStandard.Library.NETFramework</NuGetPackageId>
53+
<NuGetPackageVersion>$(NETStandardLibraryPackageVersion)</NuGetPackageVersion>
54+
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
55+
<NuGetSourceType>Package</NuGetSourceType>
56+
</ReferenceCopyLocalPaths>
57+
</ItemGroup>
58+
</Target>
59+
</Project>

pkg/NETStandard.Library.NETFramework/targets/net461/NETStandard.Library.NETFramework.targets

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,10 @@
22
<ItemGroup Condition="'$(ImplicitlyExpandNETStandardFacades)' == 'true'">
33
<_NETStandardLibraryNETFrameworkReference Include="$(MSBuildThisFileDirectory)\ref\*.dll"
44
Exclude="@(_NETStandardLibraryNETFrameworkReference->'$(MSBuildThisFileDirectory)\ref\%(FileName).dll'" />
5-
<Reference Include="@(_NETStandardLibraryNETFrameworkReference)">
6-
<!-- Private = false to make these reference only -->
7-
<Private>false</Private>
8-
<NuGetPackageId>NETStandard.Library.NETFramework</NuGetPackageId>
9-
<NuGetPackageVersion>$(NETStandardLibraryNETFrameworkPackageVersion)</NuGetPackageVersion>
10-
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
11-
<NuGetSourceType>Package</NuGetSourceType>
12-
</Reference>
135

146
<_NETStandardLibraryNETFrameworkLib Include="$(MSBuildThisFileDirectory)\lib\*.dll"
157
Exclude="@(_NETStandardLibraryNETFrameworkLib->'$(MSBuildThisFileDirectory)\ref\%(FileName).dll'" />
16-
<ReferenceCopyLocalPaths Include="@(_NETStandardLibraryNETFrameworkLib)">
17-
<Private>false</Private>
18-
<NuGetPackageId>NETStandard.Library.NETFramework</NuGetPackageId>
19-
<NuGetPackageVersion>$(NETStandardLibraryPackageVersion)</NuGetPackageVersion>
20-
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
21-
<NuGetSourceType>Package</NuGetSourceType>
22-
</ReferenceCopyLocalPaths>
238
</ItemGroup>
9+
10+
<Import Project="..\$(MSBuildThisFileName).common.targets" />
2411
</Project>

pkg/NETStandard.Library.NETFramework/targets/net462/NETStandard.Library.NETFramework.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
</ItemGroup>
99

1010
<Import Project="..\net461\$(MSBuildThisFile)" />
11+
<Import Project="..\$(MSBuildThisFileName).common.targets" />
1112
</Project>

pkg/NETStandard.Library.NETFramework/targets/net47/NETStandard.Library.NETFramework.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
</ItemGroup>
99

1010
<Import Project="..\net462\$(MSBuildThisFile)" />
11+
<Import Project="..\$(MSBuildThisFileName).common.targets" />
1112
</Project>

0 commit comments

Comments
 (0)