Skip to content

Commit

Permalink
Merge pull request #6924 from dsplaisted/stop-selfcontained-flow
Browse files Browse the repository at this point in the history
Don't flow self contained command-line option to referenced projects
  • Loading branch information
dsplaisted authored Aug 19, 2022
2 parents daa594b + 512a065 commit e1716a1
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Shared/ConversionUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal static bool ValidBooleanTrue(string parameterValue)
/// Returns true if the string represents a valid MSBuild boolean false value,
/// such as "!on" "off" "no" "!true"
/// </summary>
private static bool ValidBooleanFalse(string parameterValue)
internal static bool ValidBooleanFalse(string parameterValue)
{
return String.Equals(parameterValue, "false", StringComparison.OrdinalIgnoreCase) ||
String.Equals(parameterValue, "off", StringComparison.OrdinalIgnoreCase) ||
Expand Down
7 changes: 4 additions & 3 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Shared\FileSystemSources.proj" />
<Import Project="..\Shared\DebuggingSources.proj" />
Expand Down Expand Up @@ -329,6 +329,7 @@
</Compile>
<Compile Include="ResourceHandling\*.cs" />
<Compile Include="GetCompatiblePlatform.cs" />
<Compile Include="SetRidAgnosticValueForProjects.cs" />
<Compile Include="ResolveComReference.cs" />
<Compile Include="BuildCacheDisposeWrapper.cs" />
<Compile Include="DownloadFile.cs" />
Expand Down Expand Up @@ -966,8 +967,8 @@
<ItemGroup>
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" SetTargetFramework="TargetFramework=netstandard2.0" OutputItemType="NetstandardRefAssemblies" />
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj" SetTargetFramework="TargetFramework=netstandard2.0" OutputItemType="NetstandardRefAssemblies" />
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj"/>
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj"/>
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" />
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj" />
<ProjectReference Include="..\StringTools\StringTools.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions src/Tasks/Microsoft.Common.CrossTargeting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<TargetPlatformMonikers>@(_TargetFrameworkInfo->'%(TargetPlatformMonikers)')</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalPropertiesFromProject)</AdditionalPropertiesFromProject>
<HasSingleTargetFramework>false</HasSingleTargetFramework>
<!-- indicate to caller that project is RID agnostic so that a global property RuntimeIdentifier value can be removed -->
<IsRidAgnostic>false</IsRidAgnostic>
<IsRidAgnostic Condition=" '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</IsRidAgnostic>
<IsRidAgnostic>@(_TargetFrameworkInfo->'%(IsRidAgnostic)')</IsRidAgnostic>
<!-- Extract necessary information for SetPlatform negotiation -->
<!-- This target does not run for cpp projects. -->
<IsVcxOrNativeProj>false</IsVcxOrNativeProj>
Expand Down Expand Up @@ -220,4 +218,4 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Import Project="$(DirectoryBuildTargetsPath)" Condition="'$(ImportDirectoryBuildTargets)' == 'true' and exists('$(DirectoryBuildTargetsPath)')"/>

</Project>
</Project>
41 changes: 32 additions & 9 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
***********************************************************************************************
Microsoft.Common.CurrentVersion.targets
Expand Down Expand Up @@ -1788,7 +1788,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier$(_GlobalPropertiesToRemoveFromProjectReferences)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier;SelfContained;$(_GlobalPropertiesToRemoveFromProjectReferences)"
Condition="'%(_MSBuildProjectReferenceExistent.SkipGetTargetFrameworkProperties)' != 'true' and '$(EnableDynamicPlatformResolution)' != 'true'"
SkipNonexistentTargets="true">
<Output TaskParameter="TargetOutputs" ItemName="_ProjectReferenceTargetFrameworkPossibilities" />
Expand All @@ -1804,7 +1804,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Targets="GetTargetFrameworks"
BuildInParallel="$(BuildInParallel)"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier;Platform;Configuration$(_GlobalPropertiesToRemoveFromProjectReferences)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier;SelfContained;Platform;Configuration;$(_GlobalPropertiesToRemoveFromProjectReferences)"
Condition="'%(_MSBuildProjectReferenceExistent.SkipGetTargetFrameworkProperties)' != 'true' and '$(EnableDynamicPlatformResolution)' == 'true'"
SkipNonexistentTargets="true">
<Output TaskParameter="TargetOutputs" ItemName="_ProjectReferenceTargetFrameworkPossibilities" />
Expand Down Expand Up @@ -1859,6 +1859,20 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Condition="'$(ReferringTargetFrameworkForProjectReferences)' == '' or
('$(EnableDynamicPlatformResolution)' == 'true' and '%(_ProjectReferenceTargetFrameworkPossibilities.IsVcxOrNativeProj)' == 'true')" />

</ItemGroup>

<!-- IsRidAgnostic metadata is used to determine whether global properties such as RuntimeIdentifier and SelfContained flow to a referenced project.
However, for multi-targeted projects there may be a different IsRidAgnostic value for each TargetFramework. In that case, this task selects
the IsRidAgnostic value for the NearestTargetFramework for the project. -->
<SetRidAgnosticValueForProjects Projects="@(AnnotatedProjects)">
<Output ItemName="UpdatedAnnotatedProjects" TaskParameter="UpdatedProjects" />
</SetRidAgnosticValueForProjects>

<ItemGroup>
<AnnotatedProjects Remove="@(AnnotatedProjects)" />
<AnnotatedProjects Include="@(UpdatedAnnotatedProjects)" />
<UpdatedAnnotatedProjects Remove="@(UpdatedAnnotatedProjects)" />

<!-- If the NearestTargetFramework property was set and the project multi-targets, SetTargetFramework must be set. -->
<AnnotatedProjects Condition="'@(AnnotatedProjects)' == '%(Identity)' and '%(AnnotatedProjects.NearestTargetFramework)' != '' and '%(AnnotatedProjects.HasSingleTargetFramework)' != 'true'">
<SetTargetFramework>TargetFramework=%(AnnotatedProjects.NearestTargetFramework)</SetTargetFramework>
Expand All @@ -1872,9 +1886,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<UndefineProperties>%(AnnotatedProjects.UndefineProperties);TargetFramework</UndefineProperties>
</AnnotatedProjects>

<!-- If the project is RID agnostic, undefine the RuntimeIdentifier property to avoid another evaluation. -->
<AnnotatedProjects Condition="'@(AnnotatedProjects)' == '%(Identity)' and '%(AnnotatedProjects.IsRidAgnostic)' == 'true'">
<UndefineProperties>%(AnnotatedProjects.UndefineProperties);RuntimeIdentifier</UndefineProperties>
<!-- Add RuntimeIdentifier and SelfContained to the list of global properties that should not flow to the referenced project,
unless the project is expecting those properties to flow. -->
<AnnotatedProjects Condition="'@(AnnotatedProjects)' == '%(Identity)' and '%(AnnotatedProjects.IsRidAgnostic)' != 'false'">
<UndefineProperties>%(AnnotatedProjects.UndefineProperties);RuntimeIdentifier;SelfContained</UndefineProperties>
</AnnotatedProjects>

<!--
Expand Down Expand Up @@ -1907,9 +1922,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<TargetPlatformMonikers>@(_TargetFrameworkInfo->'%(TargetPlatformMonikers)')</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalPropertiesFromProject)</AdditionalPropertiesFromProject>
<HasSingleTargetFramework>true</HasSingleTargetFramework>
<!-- indicate to caller that project is RID agnostic so that a global property RuntimeIdentifier value can be removed -->
<IsRidAgnostic>false</IsRidAgnostic>
<IsRidAgnostic Condition=" '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</IsRidAgnostic>
<IsRidAgnostic>@(_TargetFrameworkInfo->'%(IsRidAgnostic)')</IsRidAgnostic>
<!-- Extract necessary information for SetPlatform negotiation -->
<IsVcxOrNativeProj Condition="'$(MSBuildProjectExtension)' == '.vcxproj' or '$(MSBuildProjectExtension)' == '.nativeproj'">true</IsVcxOrNativeProj>
<Platform Condition="$([MSBuild]::AreFeaturesEnabled('17.4'))">$(Platform)</Platform>
Expand Down Expand Up @@ -1950,6 +1963,16 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<TargetPlatformMonikers>$(TargetPlatformMoniker)</TargetPlatformMonikers>
<TargetPlatformMonikers Condition="'$(TargetPlatformMoniker)' == ''">None</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalTargetFrameworkInfoProperties)</AdditionalPropertiesFromProject>

<!-- Determine whether a project is "RID agnostic" for each TargetFramework. "RID agnostic" means that global properties such as SelfContained and RuntimeIdentifier should
not flow across project references.
Generally this value will come from the IsRidAgnostic property set by the .NET SDK. If that's not set, then the fallback logic here will be that the project
is RID agnostic if it doesn't have RuntimeIdentifier or RuntimeIdentifiers properties set. -->
<IsRidAgnostic>$(IsRidAgnostic)</IsRidAgnostic>
<IsRidAgnostic Condition=" '$(IsRidAgnostic)' == '' and '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</IsRidAgnostic>
<IsRidAgnostic Condition=" '$(IsRidAgnostic)' == ''">false</IsRidAgnostic>

</_TargetFrameworkInfo>
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion src/Tasks/Microsoft.Common.tasks
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<UsingTask TaskName="Microsoft.Build.Tasks.GetFrameworkPath" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.GetFrameworkSdkPath" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.GetReferenceAssemblyPaths" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.SetRidAgnosticValueForProjects" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.Hash" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.LC" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Microsoft.Build.Tasks.MakeDir" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Expand Down Expand Up @@ -106,4 +107,4 @@
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />

</Project>
</Project>
9 changes: 8 additions & 1 deletion src/Tasks/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Projects.get -> Microsoft.Build.Framework.ITaskItem[]
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Projects.set -> void
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.SetRidAgnosticValueForProjects() -> void
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.UpdatedProjects.get -> Microsoft.Build.Framework.ITaskItem[]
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.UpdatedProjects.set -> void
override Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Execute() -> bool
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.get -> bool
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.set -> void
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.set -> void
9 changes: 8 additions & 1 deletion src/Tasks/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Projects.get -> Microsoft.Build.Framework.ITaskItem[]
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Projects.set -> void
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.SetRidAgnosticValueForProjects() -> void
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.UpdatedProjects.get -> Microsoft.Build.Framework.ITaskItem[]
Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.UpdatedProjects.set -> void
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.get -> bool
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.set -> void
Microsoft.Build.Tasks.XslTransformation.PreserveWhitespace.set -> void
override Microsoft.Build.Tasks.SetRidAgnosticValueForProjects.Execute() -> bool
65 changes: 65 additions & 0 deletions src/Tasks/SetRidAgnosticValueForProjects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Utilities;

namespace Microsoft.Build.Tasks
{
public sealed class SetRidAgnosticValueForProjects : TaskExtension
{
public ITaskItem[] Projects { get; set; } = Array.Empty<ITaskItem>();

[Output]
public ITaskItem[] UpdatedProjects { get; set; } = Array.Empty<ITaskItem>();

public override bool Execute()
{
UpdatedProjects = Projects
.Select(p =>
{
var hasSingleTargetFrameworkString = p.GetMetadata("HasSingleTargetFramework");
if (!ConversionUtilities.ValidBooleanFalse(hasSingleTargetFrameworkString))
{
// No change to item, it should already have a single-valued IsRidAgnostic value
return p;
}
var updatedItem = new TaskItem(p);
var nearestTargetFramework = p.GetMetadata("NearestTargetFramework");
if (string.IsNullOrEmpty(nearestTargetFramework))
{
return p;
}
var targetFrameworksArray = p.GetMetadata("TargetFrameworks").Split(';');
int targetFrameworkIndex = Array.IndexOf(targetFrameworksArray, nearestTargetFramework);
if (targetFrameworkIndex < 0)
{
return p;
}
var isRidAgnosticArray = p.GetMetadata("IsRidAgnostic").Split(';');
if (isRidAgnosticArray.Length != targetFrameworksArray.Length)
{
return p;
}
updatedItem.SetMetadata("IsRidAgnostic", isRidAgnosticArray[targetFrameworkIndex]);
return updatedItem;
})
.ToArray();

return true;
}
}
}

0 comments on commit e1716a1

Please sign in to comment.