Skip to content

Commit

Permalink
Improve SDK Pack compatibility for framework-specific tools
Browse files Browse the repository at this point in the history
SDK Pack always packs tools as framework-specific, so we
default to doing the same.

Fixes #132

tools
  • Loading branch information
kzu committed Jul 20, 2021
1 parent a709978 commit f224aaa
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/NuGetizer.Tasks/AssignPackagePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,26 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, ITaskItem> kindM
// If we have no known package folder, files go to their RelativeDir location.
// This allows custom packaging paths such as "workbooks", "docs" or whatever, which aren't prohibited by
// the format.
packagePath = string.IsNullOrEmpty(packageFolder) ?
if (string.IsNullOrEmpty(packageFolder))
{
// File goes to the determined target path (or the root of the package), such as a readme.txt
targetPath :
frameworkSpecific ?
// Otherwise, it goes to a framework-specific folder.
Path.Combine(new[] { packageFolder, targetFramework }.Concat(targetPath.Split(Path.DirectorySeparatorChar)).ToArray()) :
// Except if frameworkSpecific is false, such as for build, tools, runtimes
Path.Combine(new[] { packageFolder }.Concat(targetPath.Split(Path.DirectorySeparatorChar)).ToArray());
packagePath = targetPath;
}
else
{
if (frameworkSpecific)
{
// For (framework-specific) tools, we need to append 'any' at the end
if (packageFolder == PackagingConstants.Folders.Tools)
packagePath = Path.Combine(new[] { packageFolder, targetFramework, "any" }.Concat(targetPath.Split(Path.DirectorySeparatorChar)).ToArray());
else
packagePath = Path.Combine(new[] { packageFolder, targetFramework }.Concat(targetPath.Split(Path.DirectorySeparatorChar)).ToArray());
}
else
{
packagePath = Path.Combine(new[] { packageFolder }.Concat(targetPath.Split(Path.DirectorySeparatorChar)).ToArray());
}
}

output.SetMetadata(MetadataName.PackagePath, packagePath);

Expand Down
1 change: 1 addition & 0 deletions src/NuGetizer.Tasks/NuGetizer.props
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</PackFolderKind>
<PackFolderKind Include="Tool;Tools">
<PackageFolder>tools</PackageFolder>
<FrameworkSpecific>true</FrameworkSpecific>
</PackFolderKind>
<PackFolderKind Include="Native">
<PackageFolder>native</PackageFolder>
Expand Down
38 changes: 38 additions & 0 deletions src/NuGetizer.Tests/AssignPackagePathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,13 @@ public void when_file_is_not_framework_specific_then_it_is_not_assigned_target_f
{ "PackageId", "A" },
{ "TargetFrameworkMoniker", ".NETFramework,Version=v4.5" },
{ "PackFolder", "tools" },
{ "FrameworkSpecific", "false" },
}),
new TaskItem("docs\\index.html", new Metadata
{
{ "PackageId", "A" },
{ "TargetFrameworkMoniker", ".NETFramework,Version=v4.5" },
{ "PackFolder", "none" },
})
}
};
Expand All @@ -858,6 +865,37 @@ public void when_file_is_not_framework_specific_then_it_is_not_assigned_target_f
PackagePath = @"tools\foo.exe",
TargetFramework = "",
}));
Assert.Contains(task.AssignedFiles, item => item.Matches(new
{
PackagePath = @"docs\index.html",
TargetFramework = "",
}));
}

[Fact]
public void when_packing_tool_then_it_is_framework_specific_and_any()
{
var task = new AssignPackagePath
{
BuildEngine = engine,
KnownFolders = Kinds,
Files = new ITaskItem[]
{
new TaskItem("tools\\foo.exe", new Metadata
{
{ "PackageId", "A" },
{ "TargetFrameworkMoniker", ".NETFramework,Version=v4.5" },
{ "PackFolder", "tools" },
}),
}
};

Assert.True(task.Execute());
Assert.Contains(task.AssignedFiles, item => item.Matches(new
{
PackagePath = @"tools\net45\any\foo.exe",
TargetFramework = "net45",
}));
}
}
}

0 comments on commit f224aaa

Please sign in to comment.