Skip to content

Commit e9e81db

Browse files
committed
Move @(Reference) -> @(ProjectReference) conversion into a target
1 parent e956062 commit e9e81db

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

eng/targets/ResolveReferences.targets

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
<_AllowedExplicitPackageReference Include="FSharp.Core" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
7676
<_ExplicitPackageReference Include="@(PackageReference)" Exclude="@(_ImplicitPackageReference);@(_AllowedExplicitPackageReference)" />
7777

78-
<_UnusedProjectReferenceProvider Include="@(ProjectReferenceProvider)" Exclude="@(Reference)" />
79-
8078
<_CompilationOnlyReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="@(Reference->WithMetadataValue('NuGetPackageId','NETStandard.Library'))" />
8179

8280
<_InvalidReferenceToNonSharedFxAssembly Condition="'$(IsAspNetCoreApp)' == 'true'"
@@ -87,26 +85,42 @@
8785
@(ExternalAspNetCoreAppReference);
8886
@(_CompilationOnlyReference);
8987
@(Reference->WithMetadataValue('IsSharedSource', 'true'))" />
88+
9089
<_OriginalReferences Include="@(Reference)" />
91-
<!--
92-
Turn Reference items into a ProjectReference when UseProjectReferences is true.
93-
Order matters. This comes before package resolution because projects should be used when possible instead of packages.
94-
-->
95-
<_ProjectReferenceByAssemblyName Condition="'$(UseProjectReferences)' == 'true'"
96-
Include="@(ProjectReferenceProvider)"
97-
Exclude="@(_UnusedProjectReferenceProvider)" />
90+
</ItemGroup>
9891

99-
<!-- Use ref assembly project paths for ref assembly projects -->
100-
<ProjectReference Condition="'$(ReferenceImplementationAssemblies)' == 'true'" Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')" >
101-
<IsReferenceAssembly>false</IsReferenceAssembly>
102-
</ProjectReference>
92+
<!--
93+
Turn Reference items into a ProjectReference when UseProjectReferences is true. Order matters. This comes before
94+
package resolution (e.g. ResolveCustomReferences) because projects should be used when possible instead of packages.
10395
104-
<ProjectReference Condition="'$(ReferenceReferenceAssemblies)' == 'true'" Include="@(_ProjectReferenceByAssemblyName->'%(RefProjectPath)')" >
105-
<IsReferenceAssembly>true</IsReferenceAssembly>
106-
</ProjectReference>
96+
As .NET SDK changes, watch for problems in this target. The BeforeTargets list is a hack required because the SDK
97+
generally assumes all @(ProjectReference) items are statically defined. Main problem is reliance on internal
98+
(therefore fragile) target names.
99+
-->
100+
<Target Name="ResolveCustomReferencesToProjects"
101+
Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true' AND '$(UseProjectReferences)' == 'true' "
102+
BeforeTargets="AssignProjectConfiguration;ResolveCustomReferences;_LoadRestoreGraphEntryPoints;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreProjectPathItemsPerFramework">
103+
<JoinItems Left="@(Reference)" Right="@(ProjectReferenceProvider)" LeftMetadata="*" RightMetadata="ProjectPath;RefProjectPath">
104+
<Output TaskParameter="JoinResult" ItemName="_ProjectReferenceByAssemblyName" />
105+
</JoinItems>
107106

108-
<Reference Remove="@(_ProjectReferenceByAssemblyName)" />
109-
</ItemGroup>
107+
<ItemGroup>
108+
<!-- Use ref assembly project paths for ref assembly projects -->
109+
<ProjectReference Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')"
110+
Condition="'$(ReferenceImplementationAssemblies)' == 'true'">
111+
<IsReferenceAssembly>false</IsReferenceAssembly>
112+
<ReferenceOutputAssembly Condition=" '%(_ProjectReferenceByAssemblyName.PrivateAssets)' == 'all' ">false</ReferenceOutputAssembly>
113+
</ProjectReference>
114+
115+
<ProjectReference Include="@(_ProjectReferenceByAssemblyName->'%(RefProjectPath)')"
116+
Condition="'$(ReferenceReferenceAssemblies)' == 'true'">
117+
<IsReferenceAssembly>true</IsReferenceAssembly>
118+
<ReferenceOutputAssembly Condition=" '%(_ProjectReferenceByAssemblyName.PrivateAssets)' == 'all' ">false</ReferenceOutputAssembly>
119+
</ProjectReference>
120+
121+
<Reference Remove="@(_ProjectReferenceByAssemblyName)" />
122+
</ItemGroup>
123+
</Target>
110124

111125
<!--
112126
This target resolves remaining Referene items to Packages, if possible. If not, they are left as Reference items fo the SDK to resolve.

0 commit comments

Comments
 (0)