Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't evaluate outer build targets in inner build #8434

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemDefinitionGroup>

<PropertyGroup>
<DotNetBuildTasksTargetFrameworkAssembly Condition="'$(DotNetBuildTasksTargetFrameworkAssembly)' == '' and '$(MSBuildRuntimeType)' == 'core'">..\tools\netcoreapp3.1\Microsoft.DotNet.Build.Tasks.TargetFramework.dll</DotNetBuildTasksTargetFrameworkAssembly>
<DotNetBuildTasksTargetFrameworkAssembly Condition="'$(DotNetBuildTasksTargetFrameworkAssembly)' == '' and '$(MSBuildRuntimeType)' != 'core'">..\tools\net472\Microsoft.DotNet.Build.Tasks.TargetFramework.dll</DotNetBuildTasksTargetFrameworkAssembly>
<DotNetBuildTasksTargetFrameworkAssembly Condition="'$(MSBuildRuntimeType)' == 'core'">..\tools\netcoreapp3.1\Microsoft.DotNet.Build.Tasks.TargetFramework.dll</DotNetBuildTasksTargetFrameworkAssembly>
<DotNetBuildTasksTargetFrameworkAssembly Condition="'$(MSBuildRuntimeType)' != 'core'">..\tools\net472\Microsoft.DotNet.Build.Tasks.TargetFramework.dll</DotNetBuildTasksTargetFrameworkAssembly>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,57 +1,7 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<UsingTask TaskName="ChooseBestP2PTargetFrameworkTask" AssemblyFile="$(DotNetBuildTasksTargetFrameworkAssembly)" />
<UsingTask TaskName="ChooseBestTargetFrameworksTask" AssemblyFile="$(DotNetBuildTasksTargetFrameworkAssembly)" />

<!-- We filter _InnerBuildProjects items during DispatchToInnerBuilds and Clean to only run for best target frameworks. -->
<Target Name="RunOnlyBestTargetFrameworks"
Condition="'$(IsCrossTargetingBuild)' == 'true' and '$(BuildTargetFramework)' != ''"
BeforeTargets="DispatchToInnerBuilds;Clean"
DependsOnTargets="GetProjectWithBestTargetFrameworks">
<ItemGroup>
<_OriginalInnerBuildProjects Include="@(_InnerBuildProjects)" />
<_InnerBuildProjects Remove="@(_InnerBuildProjects)" />
<_InnerBuildProjects Include="@(InnerBuildProjectsWithBestTargetFramework)" />
</ItemGroup>
</Target>

<!-- As _InnerBuildProjects items are used in the GetTargetFrameworks path as well (>= .NET 5), we restore the item state. -->
<Target Name="RestoreInnerBuildProjects"
BeforeTargets="GetTargetFrameworksWithPlatformFromInnerBuilds"
AfterTargets="DispatchToInnerBuilds;Clean"
Condition="'@(_OriginalInnerBuildProjects)' != ''">
<ItemGroup>
<_InnerBuildProjects Remove="@(_InnerBuildProjects)" />
<_InnerBuildProjects Include="@(_OriginalInnerBuildProjects)" />
</ItemGroup>
</Target>

<Target Name="GetProjectWithBestTargetFrameworks">
<ItemGroup Condition="'$(BuildTargetFramework)' != ''">
<_BuildTargetFrameworkWithTargetOS Include="$(BuildTargetFramework)-$(TargetOS)" />
</ItemGroup>
<ItemGroup Condition="'$(BuildTargetFramework)' == ''">
<_BuildTargetFrameworkWithoutOS Include="$([MSBuild]::Unescape($([System.Text.RegularExpressions.Regex]::Replace('$(TargetFrameworks)', '(-[^;]+)', ''))))" />
<!-- TODO: Find a better way to filter out non applicable TargetOS values for .NET Framework. -->
<_BuildTargetFrameworkWithTargetOS Include="@(_BuildTargetFrameworkWithoutOS->Distinct()->'%(Identity)-$(TargetOS)')"
Condition="'$(TargetOS)' == 'windows' or !$([System.String]::Copy('%(Identity)').StartsWith('net4'))" />
</ItemGroup>

<ChooseBestTargetFrameworksTask BuildTargetFrameworks="@(_BuildTargetFrameworkWithTargetOS);$(AdditionalBuildTargetFrameworks)"
SupportedTargetFrameworks="$(TargetFrameworks)"
RuntimeGraph="$(RuntimeGraph)"
Distinct="true">
<Output TaskParameter="BestTargetFrameworks" ItemName="_BestTargetFramework" />
</ChooseBestTargetFrameworksTask>

<!-- Create inner build project nodes with the TargetFramework supplied via AdditionalProperties. -->
<ItemGroup>
<_BestTargetFramework Project="$(MSBuildProjectFile)" />
<InnerBuildProjectsWithBestTargetFramework Include="%(_BestTargetFramework.Project)"
AdditionalProperties="TargetFramework=%(Identity)" />
</ItemGroup>
</Target>

<!--
Runs in a leaf project (csproj) to determine best configuration for ProjectReferences.
Make sure to run late enough for transitive dependencies which runs before AssignProjectConfiguration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<Import Project="..\build\$(MSBuildThisFile)" />
<UsingTask TaskName="ChooseBestTargetFrameworksTask" AssemblyFile="$(DotNetBuildTasksTargetFrameworkAssembly)" />

<!-- We filter _InnerBuildProjects items during DispatchToInnerBuilds and Clean to only run for best target frameworks. -->
<Target Name="RunOnlyBestTargetFrameworks"
Condition="'$(BuildTargetFramework)' != ''"
BeforeTargets="DispatchToInnerBuilds;Clean"
DependsOnTargets="GetProjectWithBestTargetFrameworks">
<ItemGroup>
<_OriginalInnerBuildProjects Include="@(_InnerBuildProjects)" />
<_InnerBuildProjects Remove="@(_InnerBuildProjects)" />
<_InnerBuildProjects Include="@(InnerBuildProjectsWithBestTargetFramework)" />
</ItemGroup>
</Target>

<!-- As _InnerBuildProjects items are used in the GetTargetFrameworks path as well (>= .NET 5), we restore the item state. -->
<Target Name="RestoreInnerBuildProjects"
BeforeTargets="GetTargetFrameworksWithPlatformFromInnerBuilds"
AfterTargets="DispatchToInnerBuilds;Clean"
Condition="'@(_OriginalInnerBuildProjects)' != ''">
<ItemGroup>
<_InnerBuildProjects Remove="@(_InnerBuildProjects)" />
<_InnerBuildProjects Include="@(_OriginalInnerBuildProjects)" />
</ItemGroup>
</Target>

<Target Name="GetProjectWithBestTargetFrameworks">
<ItemGroup Condition="'$(BuildTargetFramework)' != ''">
<_BuildTargetFrameworkWithTargetOS Include="$(BuildTargetFramework)-$(TargetOS)" />
</ItemGroup>
<ItemGroup Condition="'$(BuildTargetFramework)' == ''">
<_BuildTargetFrameworkWithoutOS Include="$([MSBuild]::Unescape($([System.Text.RegularExpressions.Regex]::Replace('$(TargetFrameworks)', '(-[^;]+)', ''))))" />
<!-- TODO: Find a better way to filter out non applicable TargetOS values for .NET Framework. -->
<_BuildTargetFrameworkWithTargetOS Include="@(_BuildTargetFrameworkWithoutOS->Distinct()->'%(Identity)-$(TargetOS)')"
Condition="'$(TargetOS)' == 'windows' or !$([System.String]::Copy('%(Identity)').StartsWith('net4'))" />
</ItemGroup>

<ChooseBestTargetFrameworksTask BuildTargetFrameworks="@(_BuildTargetFrameworkWithTargetOS);$(AdditionalBuildTargetFrameworks)"
SupportedTargetFrameworks="$(TargetFrameworks)"
RuntimeGraph="$(RuntimeGraph)"
Distinct="true">
<Output TaskParameter="BestTargetFrameworks" ItemName="_BestTargetFramework" />
</ChooseBestTargetFrameworksTask>

<!-- Create inner build project nodes with the TargetFramework supplied via AdditionalProperties. -->
<ItemGroup>
<_BestTargetFramework Project="$(MSBuildProjectFile)" />
<InnerBuildProjectsWithBestTargetFramework Include="%(_BestTargetFramework.Project)"
AdditionalProperties="TargetFramework=%(Identity)" />
</ItemGroup>
</Target>
</Project>