Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Detect whether SelfContained is a global property inside task
  • Loading branch information
dsplaisted committed Aug 12, 2022
commit 45f8979059e8f787d48f8b1b01e81a7952d31992
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class ValidateExecutableReferences : TaskBase
{
public bool SelfContained { get; set; }

public bool SelfContainedIsGlobalProperty { get; set; }

public bool IsExecutable { get; set; }

public ITaskItem[] ReferencedProjects { get; set; } = Array.Empty<ITaskItem>();
Expand Down Expand Up @@ -55,7 +53,9 @@ protected override void ExecuteCore()
bool referencedProjectIsExecutable = MSBuildUtilities.ConvertStringToBool(projectAdditionalProperties["_IsExecutable"]);
bool referencedProjectIsSelfContained = MSBuildUtilities.ConvertStringToBool(projectAdditionalProperties["SelfContained"]);

if (SelfContainedIsGlobalProperty && project.GetBooleanMetadata("AcceptsRuntimeIdentifier") == true)
bool selfContainedIsGlobalProperty = BuildEngine6.GetGlobalProperties().ContainsKey("SelfContained");

if (selfContainedIsGlobalProperty && project.GetBooleanMetadata("AcceptsRuntimeIdentifier") == true)
{
// If AcceptsRuntimeIdentifier is true for the project, and SelfContained was set as a global property,
// then the SelfContained value will flow across the project reference when we go to build it, despite the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,25 +1104,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<_UseAttributeForTargetFrameworkInfoPropertyNames Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MSBuildVersion), '17.0'))">true</_UseAttributeForTargetFrameworkInfoPropertyNames>
</PropertyGroup>

<PropertyGroup>
<!-- Check if SelfContained is specified as a global property, by trying to change its value and seeing if that's successful.
We need to know if it's a global property because if it is, then it will flow to referenced projects that had
AcceptsRuntimeIdentifier set to true, possibly overriding the value for SelfContained that we got back from
the GetTargetFrameworks negotiation. -->
<_SelfContainedBackupValue>$(SelfContained)</_SelfContainedBackupValue>
<SelfContained>NotAValue</SelfContained>
<_SelfContainedIsGlobalProperty Condition="'$(SelfContained)' == '$(_SelfContainedBackupValue)'">true</_SelfContainedIsGlobalProperty>
<SelfContained>$(_SelfContainedBackupValue)</SelfContained>
<_SelfContainedBackupValue></_SelfContainedBackupValue>
</PropertyGroup>

<Target Name="ValidateExecutableReferences"
AfterTargets="_GetProjectReferenceTargetFrameworkProperties"
Condition="'$(ValidateExecutableReferencesMatchSelfContained)' != 'false'">

<ValidateExecutableReferences
SelfContained="$(SelfContained)"
SelfContainedIsGlobalProperty="$(_SelfContainedIsGlobalProperty)"
IsExecutable="$(_IsExecutable)"
ReferencedProjects="@(_MSBuildProjectReferenceExistent)"
UseAttributeForTargetFrameworkInfoPropertyNames="$(_UseAttributeForTargetFrameworkInfoPropertyNames)"
Expand Down