Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 476e800

Browse files
kzuadalon
authored andcommitted
Fix package file reference when CopyToOutput=Never
In this case, the package files should be referenced from their source path, not the outputpath-relative location. This was not working if the CopyToOutput was because we were only considering '' to mean "not copying", but 'Never' is also a valid value for the same situation.
1 parent 2c76030 commit 476e800

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Inference.targets

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,23 @@ Copyright (c) .NET Foundation. All rights reserved.
107107
<!-- NOTE: Content is opt-out (must have Pack=false to exclude if IncludeContentInPackage=true) -->
108108
<!-- Stuff that is copied to output should be included from that output location -->
109109
<_InferredPackageFile Include="@(_ContentToInfer->'$(OutputPath)%(TargetPath)')"
110-
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' != ''">
110+
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' != '' and '%(_ContentToInfer.CopyToOutputDirectory)' != 'Never'">
111111
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">$(PrimaryOutputKind)</Kind>
112112
</_InferredPackageFile>
113113
<!-- Otherwise, include from source location and default to content -->
114114
<_InferredPackageFile Include="@(_ContentToInfer->'%(FullPath)')"
115-
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' == ''">
115+
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' == '' or '%(_ContentToInfer.CopyToOutputDirectory)' == 'Never'">
116116
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">Content</Kind>
117117
</_InferredPackageFile>
118118

119119
<!-- NOTE: None is also opt-out (must have Pack=false to exclude if IncludeNoneInPackage=true, but this property defaults to false) -->
120120
<!-- Likewise, include from target path if it's copied, from source path otherwise -->
121121
<_InferredPackageFile Include="@(_NoneToInfer->'$(OutputPath)%(TargetPath)')"
122-
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' != ''">
122+
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' != '' and '%(_NoneToInfer.CopyToOutputDirectory)' != 'Never'">
123123
<Kind Condition="'%(_NoneToInfer.Kind)' == ''">$(PrimaryOutputKind)</Kind>
124124
</_InferredPackageFile>
125125
<_InferredPackageFile Include="@(_NoneToInfer->'%(FullPath)')"
126-
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' == ''">
126+
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' == '' or '%(_NoneToInfer.CopyToOutputDirectory)' == 'Never'">
127127
<Kind Condition="'%(_NoneToInfer.Kind)' == ''">None</Kind>
128128
</_InferredPackageFile>
129129

src/Build/NuGet.Build.Packaging.Tests/Builder.NuGetizer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@ public static TargetResult BuildScenario(string scenarioName, object properties
6262
buildProps[nameof(ThisAssembly.Project.Properties.NuGetRestoreTargets)] = ThisAssembly.Project.Properties.NuGetRestoreTargets;
6363
buildProps[nameof(ThisAssembly.Project.Properties.NuGetTargets)] = ThisAssembly.Project.Properties.NuGetTargets;
6464

65-
return new TargetResult(Build(projectOrSolution, target,
65+
return new TargetResult(projectOrSolution, Build(projectOrSolution, target,
6666
properties: buildProps,
6767
logger: logger), target, logger);
6868
}
6969

7070
public class TargetResult : ITargetResult
7171
{
72-
public TargetResult(BuildResult result, string target, TestOutputLogger logger)
72+
public TargetResult(string projectOrSolutionFile, BuildResult result, string target, TestOutputLogger logger)
7373
{
74+
ProjectOrSolutionFile = projectOrSolutionFile;
7475
BuildResult = result;
7576
Target = target;
7677
Logger = logger;
7778
}
7879

80+
public string ProjectOrSolutionFile { get; private set; }
81+
7982
public BuildResult BuildResult { get; private set; }
8083

8184
public TestOutputLogger Logger { get; private set; }

src/Build/NuGet.Build.Packaging.Tests/NuGet.Build.Packaging.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4040
</Content>
4141
</ItemGroup>
42+
<ItemGroup>
43+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
44+
</ItemGroup>
4245
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), NuGet.Build.Packaging.Shared.targets))\NuGet.Build.Packaging.Shared.targets" />
4346
</Project>

src/Build/NuGet.Build.Packaging.Tests/given_a_library_with_content.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.IO;
2+
using System.Linq;
23
using Microsoft.Build.Execution;
34
using NuGet.Build.Packaging.Properties;
45
using Xunit;
@@ -136,6 +137,24 @@ public void content_no_copy_is_content_files_anylang_tfm_specific()
136137
}));
137138
}
138139

140+
[Fact]
141+
public void content_no_copy_is_included_from_source()
142+
{
143+
var result = Builder.BuildScenario(nameof(given_a_library_with_content), new
144+
{
145+
PackageId = "ContentPackage"
146+
});
147+
148+
result.AssertSuccess(output);
149+
150+
var sourcePath = Path.Combine(Path.GetDirectoryName(result.ProjectOrSolutionFile), "content-with-kind.txt");
151+
152+
Assert.Contains(result.Items, item => item.Matches(new
153+
{
154+
FullPath = sourcePath,
155+
}));
156+
}
157+
139158
[Fact]
140159
public void content_no_copy_with_contentFiles_dir_fails()
141160
{
@@ -495,6 +514,24 @@ public void none_with_kind_is_included_as_kind()
495514
}));
496515
}
497516

517+
[Fact]
518+
public void none_with_kind_is_included_from_source()
519+
{
520+
var result = Builder.BuildScenario(nameof(given_a_library_with_content), new
521+
{
522+
PackageId = "ContentPackage"
523+
});
524+
525+
result.AssertSuccess(output);
526+
527+
var sourcePath = Path.Combine(Path.GetDirectoryName(result.ProjectOrSolutionFile), "none-with-kind.txt");
528+
529+
Assert.Contains(result.Items, item => item.Matches(new
530+
{
531+
FullPath = sourcePath,
532+
}));
533+
}
534+
498535
[Fact]
499536
public void none_no_kind_is_included__as_none()
500537
{

0 commit comments

Comments
 (0)