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

Commit

Permalink
Fix package file reference when CopyToOutput=Never
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kzu authored and adalon committed Jun 21, 2017
1 parent 2c76030 commit 476e800
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- NOTE: Content is opt-out (must have Pack=false to exclude if IncludeContentInPackage=true) -->
<!-- Stuff that is copied to output should be included from that output location -->
<_InferredPackageFile Include="@(_ContentToInfer->'$(OutputPath)%(TargetPath)')"
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' != ''">
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' != '' and '%(_ContentToInfer.CopyToOutputDirectory)' != 'Never'">
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">$(PrimaryOutputKind)</Kind>
</_InferredPackageFile>
<!-- Otherwise, include from source location and default to content -->
<_InferredPackageFile Include="@(_ContentToInfer->'%(FullPath)')"
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' == ''">
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' == '' or '%(_ContentToInfer.CopyToOutputDirectory)' == 'Never'">
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">Content</Kind>
</_InferredPackageFile>

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

Expand Down
7 changes: 5 additions & 2 deletions src/Build/NuGet.Build.Packaging.Tests/Builder.NuGetizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ public static TargetResult BuildScenario(string scenarioName, object properties
buildProps[nameof(ThisAssembly.Project.Properties.NuGetRestoreTargets)] = ThisAssembly.Project.Properties.NuGetRestoreTargets;
buildProps[nameof(ThisAssembly.Project.Properties.NuGetTargets)] = ThisAssembly.Project.Properties.NuGetTargets;

return new TargetResult(Build(projectOrSolution, target,
return new TargetResult(projectOrSolution, Build(projectOrSolution, target,
properties: buildProps,
logger: logger), target, logger);
}

public class TargetResult : ITargetResult
{
public TargetResult(BuildResult result, string target, TestOutputLogger logger)
public TargetResult(string projectOrSolutionFile, BuildResult result, string target, TestOutputLogger logger)
{
ProjectOrSolutionFile = projectOrSolutionFile;
BuildResult = result;
Target = target;
Logger = logger;
}

public string ProjectOrSolutionFile { get; private set; }

public BuildResult BuildResult { get; private set; }

public TestOutputLogger Logger { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), NuGet.Build.Packaging.Shared.targets))\NuGet.Build.Packaging.Shared.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.IO;
using System.Linq;
using Microsoft.Build.Execution;
using NuGet.Build.Packaging.Properties;
using Xunit;
Expand Down Expand Up @@ -136,6 +137,24 @@ public void content_no_copy_is_content_files_anylang_tfm_specific()
}));
}

[Fact]
public void content_no_copy_is_included_from_source()
{
var result = Builder.BuildScenario(nameof(given_a_library_with_content), new
{
PackageId = "ContentPackage"
});

result.AssertSuccess(output);

var sourcePath = Path.Combine(Path.GetDirectoryName(result.ProjectOrSolutionFile), "content-with-kind.txt");

Assert.Contains(result.Items, item => item.Matches(new
{
FullPath = sourcePath,
}));
}

[Fact]
public void content_no_copy_with_contentFiles_dir_fails()
{
Expand Down Expand Up @@ -495,6 +514,24 @@ public void none_with_kind_is_included_as_kind()
}));
}

[Fact]
public void none_with_kind_is_included_from_source()
{
var result = Builder.BuildScenario(nameof(given_a_library_with_content), new
{
PackageId = "ContentPackage"
});

result.AssertSuccess(output);

var sourcePath = Path.Combine(Path.GetDirectoryName(result.ProjectOrSolutionFile), "none-with-kind.txt");

Assert.Contains(result.Items, item => item.Matches(new
{
FullPath = sourcePath,
}));
}

[Fact]
public void none_no_kind_is_included__as_none()
{
Expand Down

0 comments on commit 476e800

Please sign in to comment.