Skip to content

Commit

Permalink
Remove unnecessary _MSBuildProjectReferenceExistent references (#1001)
Browse files Browse the repository at this point in the history
Fix #3865
  • Loading branch information
joelverhagen authored Nov 8, 2016
1 parent 1ebf605 commit 07a6ea2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
89 changes: 43 additions & 46 deletions src/NuGet.Core/NuGet.Build.Tasks.Pack/Pack.targets
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<_TargetFrameworks Condition="'$(TargetFramework)' == ''" Include="$(TargetFrameworks.Split(';'))"/>
<_TargetFrameworks Condition="'$(TargetFramework)' != ''" Include="$(TargetFramework)"/>
</ItemGroup>

<!--
============================================================
Pack
Expand Down Expand Up @@ -126,16 +126,13 @@ Copyright (c) .NET Foundation. All rights reserved.
<PackProjectInputFile>$(MSBuildProjectFullPath)</PackProjectInputFile>
</PropertyGroup>
</Target>

<Target Name="_WalkEachTargetPerFramework">
<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="_GetProjectToProjectReferences"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
BuildProjectReferences=false;"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
BuildProjectReferences=false;">

<Output
TaskParameter="TargetOutputs"
Expand All @@ -147,10 +144,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Projects="$(MSBuildProjectFullPath)"
Targets="BuiltProjectOutputGroup;DocumentationProjectOutputGroup"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
BuildProjectReferences=false;"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
BuildProjectReferences=false;">

<Output
TaskParameter="TargetOutputs"
Expand All @@ -162,69 +156,62 @@ Copyright (c) .NET Foundation. All rights reserved.
Projects="$(MSBuildProjectFullPath)"
Targets="DebugSymbolsProjectOutputGroup"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
BuildProjectReferences=false;"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
BuildProjectReferences=false;">

<Output
TaskParameter="TargetOutputs"
ItemName="_TargetPathsToSymbols" />
</MSBuild>

<MSBuild
Condition="'$(IncludeSource)' == 'true'"
Projects="$(MSBuildProjectFullPath)"
Targets="SourceFilesProjectOutputGroup"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
BuildProjectReferences=false;"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
BuildProjectReferences=false;">

<Output
TaskParameter="TargetOutputs"
ItemName="_SourceFiles" />
</MSBuild>

<MSBuild
Projects="$(MSBuildProjectFullPath)"
Targets="_GetPackageReferences"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
BuildProjectReferences=false;"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
BuildProjectReferences=false;">

<Output
TaskParameter="TargetOutputs"
ItemName="_PackageReferences" />
</MSBuild>
</Target>

<Target Name="_AddMetadataToProjectReference"
<!--
============================================================
_GetProjectMetadata
Collects metadata for pack from child projects to be used in
the generated .nuspec of the parent project.
============================================================
-->
<Target Name="_GetProjectMetadata"
Returns="@(_ProjectReferences)">
<ItemGroup>
<_ProjectReferences Include="$(MSBuildProjectFullPath)">
<PackageId>$(PackageId)</PackageId>
<PackageVersion>$(PackageVersion)</PackageVersion>
<IncludeAssets>$(IncludeAssets)</IncludeAssets>
<ExcludeAssets>$(ExcludeAssets)</ExcludeAssets>
<PrivateAssets>$(PrivateAssets)</PrivateAssets>
<TargetFramework>$(TargetFramework)</TargetFramework>
<Type>Package</Type>
</_ProjectReferences>
</ItemGroup>
</Target>

<!--
============================================================
_GetProjectToProjectReferences
Entry point for generating the project to project references.
============================================================
-->
<Target Name="_GetProjectToProjectReferences"
Condition="$(TargetFramework) != ''"
Condition="'$(TargetFramework)' != ''"
DependsOnTargets="ResolveProjectReferences"
Returns="@(_ProjectReferences)">

Expand All @@ -236,21 +223,31 @@ Copyright (c) .NET Foundation. All rights reserved.

<MSBuild
Projects="@(ValidProjectInputForPackGraph)"
Targets="_AddMetadataToProjectReference"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration);
%(_MSBuildProjectReferenceExistent.SetPlatform);
CustomAfterMicrosoftCommonTargets=$(MSBuildThisFileFullPath);
BuildProjectReferences=false;
TargetFramework=$(TargetFramework);
IncludeAssets=%(ValidProjectInputForPackGraph.IncludeAssets);
ExcludeAssets=%(ValidProjectInputForPackGraph.ExcludeAssets);
PrivateAssets=%(ValidProjectInputForPackGraph.PrivateAssets)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Targets="_GetProjectMetadata"
Properties="CustomAfterMicrosoftCommonTargets=$(MSBuildThisFileFullPath);
CustomAfterMicrosoftCommonCrossTargetingTargets=$(MSBuildThisFileFullPath);
BuildProjectReferences=false">

<Output
TaskParameter="TargetOutputs"
ItemName="_ProjectReferences" />
ItemName="_ProjectReferencesWithoutParentData" />
</MSBuild>

<ItemGroup>
<_ProjectReferences Include="@(_ProjectReferencesWithoutParentData)">
<TargetFramework>$(TargetFramework)</TargetFramework>
<Type>Package</Type>
</_ProjectReferences>
<_ProjectReferences Condition="'%(_ProjectReferences.IncludeAssets)' == ''">
<IncludeAssets>all</IncludeAssets>
</_ProjectReferences>
<_ProjectReferences Condition="'%(_ProjectReferences.ExcludeAssets)' == ''">
<ExcludeAssets>none</ExcludeAssets>
</_ProjectReferences>
<_ProjectReferences Condition="'%(_ProjectReferences.PrivateAssets)' == ''">
<PrivateAssets>build;contentFiles;analyzers</PrivateAssets>
</_ProjectReferences>
</ItemGroup>
</Target>

<!--
Expand All @@ -263,15 +260,15 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup>
<_PackageFilesToExclude Include="@(Content)" Condition="'%(Content.Pack)' == 'false'"/>
</ItemGroup>
<!-- Include PackageFiles and Content of the project being packed -->
<!-- Include PackageFiles and Content of the project being packed -->
<ItemGroup>
<_PackageFiles Include="@(Content)" Condition=" %(Content.Pack) != 'false' " />
<_PackageFiles Include="@(Compile)" Condition=" %(Compile.Pack) == 'true' " />
<_PackageFiles Include="@(None)" Condition=" %(None.Pack) == 'true' " />
</ItemGroup>
</Target>

<!--
<!--
============================================================
_GetPackageReferences
Entry point for getting the package references for a project and it's references
Expand All @@ -291,5 +288,5 @@ Copyright (c) .NET Foundation. All rights reserved.
<Version>%(PackageReference.Version)</Version>
</_PackageReferences>
</ItemGroup>
</Target>
</Target>
</Project>
47 changes: 31 additions & 16 deletions src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,25 +533,40 @@ private void ParsePackageReference(ITaskItem packageReference, out string packag
}
}

private void GetAssetMetadata(ITaskItem packageRef, out LibraryIncludeFlags include,
private void GetAssetMetadata(
ITaskItem packageRef,
out LibraryIncludeFlags include,
out LibraryIncludeFlags suppressParent)
{
var includeAssets = packageRef.GetMetadata("IncludeAssets")
.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
var excludeAssets = packageRef.GetMetadata("ExcludeAssets")
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var privateAssets = packageRef.GetMetadata("PrivateAssets")
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var includeFlags = includeAssets.Any()
? LibraryIncludeFlagUtils.GetFlags(includeAssets)
: LibraryIncludeFlags.All;
var excludeFlags = excludeAssets.Any()
? LibraryIncludeFlagUtils.GetFlags(excludeAssets)
: LibraryIncludeFlags.None;
var includeFlags = ParseLibraryIncludeFlags(
packageRef.GetMetadata("IncludeAssets"),
LibraryIncludeFlags.All);

var excludeFlags = ParseLibraryIncludeFlags(
packageRef.GetMetadata("ExcludeAssets"),
LibraryIncludeFlags.None);

include = includeFlags & ~excludeFlags;
suppressParent = privateAssets.Any()
? LibraryIncludeFlagUtils.GetFlags(privateAssets)
: LibraryIncludeFlagUtils.DefaultSuppressParent;

suppressParent = ParseLibraryIncludeFlags(
packageRef.GetMetadata("PrivateAssets"),
LibraryIncludeFlagUtils.DefaultSuppressParent);
}

private LibraryIncludeFlags ParseLibraryIncludeFlags(string input, LibraryIncludeFlags defaultFlags)
{
if (input == null)
{
return defaultFlags;
}

var unparsedFlags = input
.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(f => f.Trim())
.Where(f => f != string.Empty)
.ToArray();

return unparsedFlags.Any() ? LibraryIncludeFlagUtils.GetFlags(unparsedFlags) : defaultFlags;
}
}
}

0 comments on commit 07a6ea2

Please sign in to comment.