Skip to content

Commit b8c2b78

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

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

eng/targets/ResolveReferences.targets

Lines changed: 55 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,60 @@
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+
157+
This is imperfect because it covers only indirect references to project reference providers (most C#
158+
implementation projects) and does not work for legacy samples or other non-.NET SDK projects.
159+
160+
Note: Project reference providers have matching assembly and project names. %(Filename) matches work :)
161+
-->
162+
<Target Name="_TestWithPatchedAssemblies"
163+
Condition=" $(UseProjectReferences) AND '$(PackagesInPatch)' != '' AND
164+
(@(ResolvedCompileFileDefinitions->Count()) != 0 OR @(RuntimeCopyLocalItems->Count()) != 0) "
165+
AfterTargets="ResolvePackageAssets"
166+
BeforeTargets="AssignProjectConfiguration;
167+
GenerateBuildDependencyFile;
168+
GeneratePublishDependencyFile;
169+
ILLink;
170+
ResolveLockFileCopyLocalFiles;
171+
ResolveLockFileReferences"
172+
DependsOnTargets="ResolvePackageAssets">
173+
<!-- Find projects patched in this build that need to be added as references. -->
174+
<ItemGroup>
175+
<_ProjectsInPatch Remove="@(_ProjectsInPatch)" />
176+
<_ProjectsInPatch Include="@(ProjectReferenceProvider->'%(ProjectPath)')"
177+
Condition=" $(PackagesInPatch.Contains(' %(ProjectReferenceProvider.Identity);')) "
178+
KeepMetadata="None" />
179+
<!-- dotnet-razorpagegenerator project is unique in overriding its package ID. -->
180+
<_ProjectsInPatch Include="@(ProjectReferenceProvider->WithMetadataValue('Identity', 'dotnet-razorpagegenerator')->'%(ProjectPath)')"
181+
Condition=" $(PackagesInPatch.Contains(' RazorPageGenerator;')) "
182+
KeepMetadata="None" />
183+
184+
<!-- Ignore unreferenced assemblies and directly-referenced projects. -->
185+
<_ProjectsToAdd Remove="@(_ProjectsToAdd)" />
186+
<!-- Condition uses same Filename metadata when evaluating the other two item groups. -->
187+
<_ProjectsToAdd Include="@(_ProjectsInPatch)"
188+
Condition=" '%(Filename)' != '' AND
189+
('@(ResolvedCompileFileDefinitions)' != '' OR '@(RuntimeCopyLocalItems)' != '') "
190+
Exclude="@(ProjectReference)" />
191+
</ItemGroup>
192+
193+
<ItemGroup Condition=" @(_ProjectsToAdd->Count()) != 0 ">
194+
<!-- Add direct project references. -->
195+
<ProjectReference Include="@(_ProjectsToAdd)" IsImplicitlyDefined="true" />
196+
197+
<!-- Remove assembly references for newly-direct project references (were from baseline packages). -->
198+
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)"
199+
Condition=" '%(Filename)' != '' AND '@(_ProjectsToAdd)' != '' " />
200+
<RuntimeCopyLocalItems Remove="@(RuntimeCopyLocalItems)"
201+
Condition=" '%(Filename)' != '' AND '@(_ProjectsToAdd)' != '' " />
202+
</ItemGroup>
203+
</Target>
204+
151205
<!-- These targets are used to generate the map of assembly name to project files. See also the /t:GenerateProjectList target in build/repo.targets. -->
152206
<Target Name="GetReferencesProvided" Returns="@(ProvidesReference)">
153207
<ItemGroup>

0 commit comments

Comments
 (0)