Skip to content

Commit

Permalink
Avoid InitialTarget in libs tree for CoreLib (dotnet#65146)
Browse files Browse the repository at this point in the history
* Avoid InitialTarget in libs tree for CoreLib

InitialTargets are quite expensive as they run for every project invocation, even if the target invoked doesn't require the InitialTarget to run. Libraries projects only have one InitialTarget for correctly referencing CoreLib which can be changed so that it runs before RAR.
  • Loading branch information
ViktorHofer authored Feb 11, 2022
1 parent 9293aab commit 5861bd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
39 changes: 30 additions & 9 deletions eng/references.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,39 @@
<_FindDependencies>false</_FindDependencies>
</PropertyGroup>

<!-- If a CoreLib ProjectReference is present, make all P2P assets non transitive. -->
<ItemGroup Condition="'@(ProjectReference)' != '' and
@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
<ProjectReference Update="@(ProjectReference)"
PrivateAssets="all" />
</ItemGroup>

<!-- Project references shouldn't be copied to the output for non test apps. -->
<ItemDefinitionGroup Condition="'$(IsTestProject)' != 'true' and '$(IsTestSupportProject)' != 'true' and '$(IsGeneratorProject)' != 'true'">
<ProjectReference>
<Private>false</Private>
</ProjectReference>
</ItemDefinitionGroup>

<ItemGroup Condition="'@(ProjectReference)' != ''">
<_coreLibProjectReference Include="@(ProjectReference->WithMetadataValue('Identity', '$(CoreLibProject)'))" />
<ProjectReference Update="@(_coreLibProjectReference)">
<!-- Don't flow TargetFramework and Platform to use same inputs and outputs as the CoreLib's build as part of the runtime. -->
<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
<Private>false</Private>
</ProjectReference>
<!-- If a CoreLib ProjectReference is present, make all P2P assets non transitive. -->
<ProjectReference Update="@(ProjectReference)"
PrivateAssets="all"
Condition="'@(_coreLibProjectReference)' != ''" />
</ItemGroup>

<!-- Disable TargetArchitectureMismatch warning when we reference CoreLib as it is platform specific. -->
<Target Name="DisableProjectReferenceArchitectureMismatchWarningForCoreLib"
Condition="'@(_coreLibProjectReference)' != ''"
BeforeTargets="ResolveAssemblyReferences">
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Target>

<!-- Filter out transitive P2Ps which should be excluded. -->
<Target Name="FilterTransitiveProjectReferences"
AfterTargets="IncludeTransitiveProjectReferences"
Expand Down Expand Up @@ -57,8 +76,10 @@
</TargetPathWithTargetPlatformMoniker>
</ItemDefinitionGroup>

<Target Name="ValidateReferenceAssemblyProjectReferences" Condition="'$(IsReferenceAssembly)' == 'true'" AfterTargets="ResolveReferences">
<Error Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' AND '%(ReferencePath.IsReferenceAssembly)' != 'true' AND '%(ReferencePath.ReferenceAssembly)' == ''"
<Target Name="ValidateReferenceAssemblyProjectReferences"
AfterTargets="ResolveReferences"
Condition="'$(IsReferenceAssembly)' == 'true'">
<Error Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IsReferenceAssembly)' != 'true' and '%(ReferencePath.ReferenceAssembly)' == ''"
Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'." />
</Target>
</Project>
20 changes: 1 addition & 19 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project InitialTargets="UpdateProjectReferencesWithAttributes">
<Project>
<PropertyGroup>
<!-- Override strong name key to default to Open for test projects,
Tests which wish to control this should set TestStrongNameKeyId. -->
Expand Down Expand Up @@ -155,24 +155,6 @@

<Import Project="$(RepositoryEngineeringDir)outerBuild.targets" Condition="'$(IsCrossTargetingBuild)' == 'true'" />

<Target Name="UpdateProjectReferencesWithAttributes" Condition="'@(ProjectReference)' != ''">
<ItemGroup>
<ProjectReference Condition="'%(Filename)' == 'System.Private.CoreLib'">
<!-- Don't flow TargetFramework and Platform to use same inputs and outputs as the CoreLib's build as part of the runtime. -->
<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<!-- Disable TargetArchitectureMismatch warning when we reference CoreLib which is platform specific. -->
<PropertyGroup Condition="@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Target>

<!--
Do not clean binplace assets in the ref targeting pack to avoid incremental build failures
when the SDK tries to resolve the assets from the FrameworkList.
Expand Down

0 comments on commit 5861bd9

Please sign in to comment.