Skip to content

Commit fb95fbc

Browse files
committed
Add @(ProjectReference) items for patched projects
- #29023 - ensure tests do not use baseline assemblies for projects in current patch
1 parent 8028cb4 commit fb95fbc

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

eng/targets/ResolveReferences.targets

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
Turn Reference items into a ProjectReference when UseProjectReferences is true.
6363
Order matters. This comes before package resolution because projects should be used when possible instead of packages.
6464
-->
65-
<_ProjectReferenceByAssemblyName Condition="'$(UseProjectReferences)' == 'true'"
65+
<_ProjectReferenceByAssemblyName Condition=" $(UseProjectReferences) "
6666
Include="@(ProjectReferenceProvider)"
6767
Exclude="@(_UnusedProjectReferenceProvider)" />
6868

@@ -148,6 +148,64 @@
148148
Text="Could not resolve this reference. Could not locate the package or project for &quot;%(Reference.Identity)&quot;" />
149149
</Target>
150150

151+
<!--
152+
Remove @(ResolvedCompileFileDefinitions) and @(RuntimeCopyLocalItems) items for patched assemblies between item
153+
generation and use. Instead, ensure @(ProjectReference) items include the patched projects. This covers indirect
154+
references and improves test coverage; @(ProjectReference) items were set correctly for direct references. Changes
155+
are necessary only in servicing builds, in the release/2.1 branch, and when building non-implementation projects.
156+
This is imperfect because it covers only project reference providers i.e. most C# implementation projects.
157+
-->
158+
<Target Name="_TestPatchedAssemblies"
159+
Condition=" $(UseProjectReferences) AND '$(PackagesInPatch)' != '' AND '$(MSBuildProjectName)' != 'TestClient' "
160+
AfterTargets="ResolvePackageAssets"
161+
BeforeTargets="AssignProjectConfiguration;
162+
GenerateBuildDependencyFile;
163+
GeneratePublishDependencyFile;
164+
ILLink;
165+
ResolveLockFileCopyLocalFiles;
166+
ResolveLockFileReferences"
167+
DependsOnTargets="ResolvePackageAssets">
168+
<!-- Find projects patched in this build. -->
169+
<ItemGroup>
170+
<_ProjectsInPatch Include="$(PackagesInPatch)">
171+
<ProjectPath>@(ProjectReferenceProvider-&gt;
172+
WithMetadataValue('Identity', '%(_ProjectsInPatch.Identity)')-&gt;'%(ProjectPath)')</ProjectPath>
173+
<!-- dotnet-razorpagegenerator is unique in overriding its package ID. -->
174+
<ProjectPath
175+
Condition=" '%(Identity)' == 'RazorPageGenerator' ">@(ProjectReferenceProvider-&gt;
176+
WithMetadataValue('Identity', 'dotnet-razorpagegenerator')-&gt;'%(ProjectPath)')</ProjectPath>
177+
</_ProjectsInPatch>
178+
</ItemGroup>
179+
<!-- Do not warn when unable to find project; many cases e.g. @aspnet/signalr are only used directly. -->
180+
<ItemGroup>
181+
<ProjectReference Include="@(_ProjectsInPatch->'%(ProjectPath)')"
182+
Exclude="@(ProjectReference)"
183+
IsImplicitlyDefined="true" />
184+
</ItemGroup>
185+
186+
<!-- Find the items that need to be removed. Project reference providers all match assembly and project names. -->
187+
<JoinItems Left="@(ResolvedCompileFileDefinitions)"
188+
LeftKey="Filename"
189+
Right="@(_ProjectsInPatch->'%(ProjectPath)')"
190+
RightKey="Filename"
191+
ItemSpecToUse="Left">
192+
<Output TaskParameter="JoinResult" ItemName="_ResolvedCompileFileDefinitionsToRemove" />
193+
</JoinItems>
194+
<JoinItems Left="@(RuntimeCopyLocalItems)"
195+
LeftKey="Filename"
196+
Right="@(_ProjectsInPatch->'%(ProjectPath)')"
197+
RightKey="Filename"
198+
ItemSpecToUse="Left">
199+
<Output TaskParameter="JoinResult" ItemName="_RuntimeCopyLocalItemsToRemove" />
200+
</JoinItems>
201+
202+
<!-- Perform the actual item removals. -->
203+
<ItemGroup>
204+
<ResolvedCompileFileDefinitions Remove="@(_ResolvedCompileFileDefinitionsToRemove)" />
205+
<RuntimeCopyLocalItems Remove="@(_RuntimeCopyLocalItemsToRemove)" />
206+
</ItemGroup>
207+
</Target>
208+
151209
<!-- These targets are used to generate the map of assembly name to project files. See also the /t:GenerateProjectList target in build/repo.targets. -->
152210
<Target Name="GetReferencesProvided" Returns="@(ProvidesReference)">
153211
<ItemGroup>

0 commit comments

Comments
 (0)