Skip to content
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
27 changes: 19 additions & 8 deletions src/NuGet.Core/NuGet.Build.Tasks/NuGet.Build.Tasks.Pack.targets
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Projects="@(_ProjectReferencesFromAssetsFile)"
Targets="_GetProjectVersion"
SkipNonexistentTargets="true"
SkipNonexistentProjects="true"
Properties="BuildProjectReferences=false;">
SkipNonexistentProjects="true">
<Output
TaskParameter="TargetOutputs"
ItemName="_ProjectReferencesWithVersions"/>
Expand All @@ -359,9 +358,21 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="_WalkEachTargetPerFramework">
<ItemGroup>
<_ProjectsWithTFM Include="$(MSBuildProjectFullPath)" AdditionalProperties="TargetFramework=%(_TargetFrameworks.Identity)" />
<_ProjectsWithTFMNoBuild Include="$(MSBuildProjectFullPath)" AdditionalProperties="TargetFramework=%(_TargetFrameworks.Identity);BuildProjectReferences=false" />

<!-- Cross-targeting: address each inner-framework instance by its TargetFramework global property. -->
<_ProjectsWithTFM Condition="'$(TargetFrameworks)' != ''" Include="$(MSBuildProjectFullPath)" AdditionalProperties="TargetFramework=%(_TargetFrameworks.Identity)" />
<!-- Single-targeting: reuse the current (already-built) instance. Adding a TargetFramework global property here would fork a redundant evaluation. -->
<_ProjectsWithTFM Condition="'$(TargetFrameworks)' == ''" Include="$(MSBuildProjectFullPath)" />

<!-- _GetFrameworkAssemblyReferences depends on ResolveReferences, which participates in the project-to-project
reference protocol. During a normal pack the referenced projects have already been built, so ResolveReferences
reuses their existing evaluation/build results (no redundant evaluations). During a no-build pack (NoBuild=true)
the references were not built, so BuildProjectReferences=false is required to prevent ResolveReferences from
invoking the Build target on them (which would fail with NETSDK1085). Reuse the already-computed _ProjectsWithTFM
items and just append the BuildProjectReferences=false global property. -->
<_FrameworkAssemblyReferenceProjects Include="@(_ProjectsWithTFM)" Condition="'$(NoBuild)' != 'true'" />
<_FrameworkAssemblyReferenceProjects Include="@(_ProjectsWithTFM)" Condition="'$(NoBuild)' == 'true'">
<AdditionalProperties>%(_ProjectsWithTFM.AdditionalProperties);BuildProjectReferences=false</AdditionalProperties>
</_FrameworkAssemblyReferenceProjects>
</ItemGroup>
<MSBuild
Condition="'$(IncludeBuildOutput)' == 'true'"
Expand Down Expand Up @@ -398,7 +409,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<MSBuild
Condition="'$(IncludeSource)' == 'true'"
Projects="@(_ProjectsWithTFMNoBuild)"
Projects="@(_ProjectsWithTFM)"
Targets="SourceFilesProjectOutputGroup"
BuildInParallel="$(BuildInParallel)">

Expand All @@ -408,7 +419,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</MSBuild>

<MSBuild
Projects="@(_ProjectsWithTFMNoBuild)"
Projects="@(_FrameworkAssemblyReferenceProjects)"
Targets="_GetFrameworkAssemblyReferences"
BuildInParallel="$(BuildInParallel)">

Expand All @@ -418,7 +429,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</MSBuild>

<MSBuild
Projects="@(_ProjectsWithTFMNoBuild)"
Projects="@(_ProjectsWithTFM)"
Targets="_GetFrameworksWithSuppressedDependencies"
BuildInParallel="$(BuildInParallel)">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,8 @@ public class ExtensionMethods
var nuspecReader = nupkgReader.NuspecReader;
// Validate the assets.
var srcItems = nupkgReader.GetFiles("src").ToArray();
Assert.Equal(4, srcItems.Length);

Comment thread
nkolev92 marked this conversation as resolved.
// At least the user-authored source files are always included.
Assert.Contains("src/ClassLibrary1/ClassLibrary1.csproj", srcItems);
Assert.Contains("src/ClassLibrary1/Class1.cs", srcItems);
Assert.Contains("src/ClassLibrary1/Extensions/ExtensionMethods.cs", srcItems);
Expand Down