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

Commit c9c2312

Browse files
committed
Default PackagePath for PackageFile with no special folder to relative
Files that have special dirs like `build`, `tools`, etc., need special treatment when resolving their TF-specific paths or not. For those that aren't "special" (None, the default), we should provide a smarter default that honors the relative dir instead of dumping everything on the root. Fixes NuGet/Home#5148
1 parent 9485b7d commit c9c2312

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/Build/NuGet.Build.Packaging.Tasks/AssignPackagePath.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, string> kindMap)
125125
// P2P references)
126126
var targetPath = file.GetMetadata("TargetPath");
127127
if (string.IsNullOrEmpty(targetPath))
128-
targetPath = file.GetMetadata("FileName") + file.GetMetadata("Extension");
128+
{
129+
targetPath = kind == PackageItemKind.None ?
130+
// For None, preserve the relative dir.
131+
file.GetMetadata("RelativeDir") + file.GetMetadata("FileName") + file.GetMetadata("Extension") :
132+
file.GetMetadata("FileName") + file.GetMetadata("Extension");
133+
}
129134

130-
// None files or those for which we know no mapping, go straight to the root folder of the package.
135+
// None files or those for which we know no mapping, go straight to the root folder of the package,
136+
// respecting their RelativeDir.
131137
// This allows custom packaging paths such as "workbooks", "docs" or whatever, which aren't prohibited by
132138
// the format.
133139
var packagePath = string.IsNullOrEmpty(packageFolder) ?

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Tasks.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<TargetExt>.dll</TargetExt>
1010
<StartupObject>NuGet.Build.Packaging.Program</StartupObject>
1111
<PackOnBuild Condition="'$(PackOnBuild)' == '' And '$(Configuration)' == 'Release'">true</PackOnBuild>
12-
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">..\..\..\out</PackageOutputPath>
12+
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">..\..\..\out</PackageOutputPath>
1313
</PropertyGroup>
1414
<ItemGroup>
1515
<Reference Include="System" />
@@ -64,7 +64,6 @@
6464
<Content Include="GenerateReferenceAssembly.csproj">
6565
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6666
</Content>
67-
<None Include="project.json" />
6867
</ItemGroup>
6968
<ItemGroup>
7069
<ProjectReference Include="..\..\..\external\ApiIntersect\ApiIntersect\ApiIntersect.csproj">

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,19 @@ public void when_assigning_content_file_with_additional_metadata_then_preserves_
442442
}
443443

444444
[Fact]
445-
public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder()
445+
public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder_and_relative_package_path()
446446
{
447447
var task = new AssignPackagePath
448448
{
449449
BuildEngine = engine,
450450
Kinds = kinds,
451451
Files = new ITaskItem[]
452452
{
453-
new TaskItem("readme.txt", new Metadata
454-
{
453+
new TaskItem(@"content\docs\readme.txt", new Metadata
454+
{
455455
{ "PackageId", "A" },
456456
{ "TargetFrameworkMoniker", ".NETFramework,Version=v4.5" },
457-
{ "Kind", "None" }
457+
{ "Kind", "None" },
458458
})
459459
}
460460
};
@@ -463,7 +463,7 @@ public void when_file_has_none_kind_then_assigned_file_has_empty_package_folder(
463463
Assert.Contains(task.AssignedFiles, item => item.Matches(new
464464
{
465465
PackageFolder = "",
466-
PackagePath = "readme.txt",
466+
PackagePath = @"content\docs\readme.txt",
467467
}));
468468
}
469469

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public given_a_library_with_project_reference(ITestOutputHelper output)
2121
[Fact]
2222
public void when_getting_package_contents_then_retrieves_main_assembly_transitively()
2323
{
24-
var result = Builder.BuildScenario(nameof(given_a_library_with_project_reference), output: output, verbosity: LoggerVerbosity.Diagnostic);
24+
var result = Builder.BuildScenario(nameof(given_a_library_with_project_reference), output: output);
2525

2626
result.AssertSuccess(output);
2727

0 commit comments

Comments
 (0)