Skip to content

Commit 062349c

Browse files
committed
Rename Kind to PackFolder
Kind as metadata for an item does not look very idiomatic. Since every other property and metadata starts with `Pack`, this renames it to `PackFolder`. The `PackFolderKind` items define the defaults now. The compatiblity targets were extended to account for the now-legacy values from previous releases as well as the pre-fork nugetizer. Update the docs accordingly too.
1 parent 4cb96d4 commit 062349c

31 files changed

+373
-316
lines changed

NuGetizer.sln

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CDF1828A-0877-4238-A218-5E4FE219F6CC}"
77
ProjectSection(SolutionItems) = preProject
88
.editorconfig = .editorconfig
9-
azure-pipelines.yml = azure-pipelines.yml
10-
.github\workflows\build.yml = .github\workflows\build.yml
119
src\Directory.Build.props = src\Directory.Build.props
1210
src\Directory.Build.targets = src\Directory.Build.targets
1311
src\NuGet.Config = src\NuGet.Config
1412
README.md = README.md
15-
.github\workflows\release.yml = .github\workflows\release.yml
1613
EndProjectSection
1714
EndProject
1815
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGetizer.Tasks", "src\NuGetizer.Tasks\NuGetizer.Tasks.csproj", "{57F59BF6-9272-4B66-98A1-334B3FDA5721}"

README.md

Lines changed: 90 additions & 32 deletions
Large diffs are not rendered by default.

src/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Import Project="NuGetizer.Tasks\$(OutputPath)NuGetizer.targets" Condition="$(IsPackable) and '$(NuGetize)' == 'true'" />
1414

1515
<PropertyGroup>
16-
<PackageItemKindFile>$(IntermediateOutputPath)PackageItemKind.g$(DefaultLanguageSourceExtension)</PackageItemKindFile>
16+
<PackFolderKindFile>$(IntermediateOutputPath)PackFolderKind.g$(DefaultLanguageSourceExtension)</PackFolderKindFile>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

src/NuGetizer.Tasks/AssignPackagePath.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace NuGetizer.Tasks
1313
/// Ensures all files have the PackagePath metadata.
1414
/// If the PackagePath was not explicitly specified,
1515
/// determine one from the project relative path and
16-
/// the TargetFramework and Kind metadata, and set it
16+
/// the TargetFramework and PackFolder metadata, and set it
1717
/// on the projected item.
1818
/// </summary>
1919
public class AssignPackagePath : Task
@@ -24,14 +24,14 @@ public class AssignPackagePath : Task
2424
public ITaskItem[] Files { get; set; }
2525

2626
[Required]
27-
public ITaskItem[] Kinds { get; set; }
27+
public ITaskItem[] KnownFolders { get; set; }
2828

2929
[Output]
3030
public ITaskItem[] AssignedFiles { get; set; }
3131

3232
public override bool Execute()
3333
{
34-
var kindMap = Kinds.ToDictionary(
34+
var kindMap = KnownFolders.ToDictionary(
3535
kind => kind.ItemSpec,
3636
StringComparer.OrdinalIgnoreCase);
3737

@@ -44,24 +44,24 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, ITaskItem> kindM
4444
{
4545
var output = new TaskItem(file);
4646

47-
// Map the Kind to a target top-level directory.
48-
var kind = file.GetMetadata("Kind");
47+
// Map the pack folder to a target top-level directory.
48+
var packFolder = file.GetMetadata("PackFolder");
4949
var packageFolder = "";
5050
var frameworkSpecific = false;
51-
if (!string.IsNullOrEmpty(kind) && kindMap.TryGetValue(kind, out var kindItem))
51+
if (!string.IsNullOrEmpty(packFolder) && kindMap.TryGetValue(packFolder, out var kindItem))
5252
{
5353
packageFolder = kindItem.GetMetadata(MetadataName.PackageFolder);
5454
bool.TryParse(kindItem.GetMetadata(MetadataName.FrameworkSpecific), out frameworkSpecific);
5555
}
56-
else if (!string.IsNullOrEmpty(kind))
56+
else if (!string.IsNullOrEmpty(packFolder))
5757
{
58-
// By convention, we just turn the first letter of Kind to lowercase and assume that
58+
// By convention, we just turn the first letter of PackFolder to lowercase and assume that
5959
// to be a valid folder kind.
60-
packageFolder = char.IsLower(kind[0]) ? kind :
61-
char.ToLower(kind[0]).ToString() + kind.Substring(1);
60+
packageFolder = char.IsLower(packFolder[0]) ? packFolder :
61+
char.ToLower(packFolder[0]).ToString() + packFolder.Substring(1);
6262
}
6363

64-
// Specific PackageFile can always override Kind-inferred FrameworkSpecific value.
64+
// Specific PackageFile can always override PackFolder-inferred FrameworkSpecific value.
6565
if (bool.TryParse(file.GetMetadata(MetadataName.FrameworkSpecific), out var frameworkSpecificOverride))
6666
frameworkSpecific = frameworkSpecificOverride;
6767

@@ -100,8 +100,8 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, ITaskItem> kindM
100100
if (string.IsNullOrEmpty(file.GetMetadata("PackageId")) && !isPackaging)
101101
return output;
102102

103-
// If we got this far but there wasn't a Kind to process, it's an error.
104-
if (string.IsNullOrEmpty(kind))
103+
// If we got this far but there wasn't a PackFolder to process, it's an error.
104+
if (string.IsNullOrEmpty(packFolder))
105105
{
106106
Log.LogErrorCode(nameof(ErrorCode.NG0010), ErrorCode.NG0010(file.ItemSpec));
107107
// We return the file anyway, since the task result will still be false.
@@ -110,7 +110,7 @@ ITaskItem EnsurePackagePath(ITaskItem file, IDictionary<string, ITaskItem> kindM
110110

111111
// If the kind is known but it isn't mapped to a folder inside the package, we're done.
112112
// Special-case None kind since that means 'leave it wherever it lands' ;)
113-
if (string.IsNullOrEmpty(packageFolder) && !kind.Equals(PackageItemKind.None, StringComparison.OrdinalIgnoreCase))
113+
if (string.IsNullOrEmpty(packageFolder) && !packFolder.Equals(PackFolderKind.None, StringComparison.OrdinalIgnoreCase))
114114
return output;
115115

116116
// Special case for contentFiles, since they can also provide a codeLanguage metadata

src/NuGetizer.Tasks/CreatePackage.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Manifest Execute(Stream output)
7878
public Manifest CreateManifest()
7979
{
8080
var metadata = new ManifestMetadata();
81-
81+
8282
metadata.Id = Manifest.GetMetadata(nameof(MetadataName.PackageId));
8383

8484
if (Manifest.TryGetMetadata(nameof(ManifestMetadata.Version), out var version))
@@ -207,7 +207,7 @@ void GenerateNuspec()
207207
void AddDependencies(Manifest manifest)
208208
{
209209
var dependencies = from item in Contents
210-
where item.GetMetadata(MetadataName.Kind) == PackageItemKind.Dependency &&
210+
where PackFolderKind.Dependency.Equals(item.GetMetadata(MetadataName.PackFolder), StringComparison.OrdinalIgnoreCase) &&
211211
!"all".Equals(item.GetMetadata(MetadataName.PrivateAssets), StringComparison.OrdinalIgnoreCase)
212212
select new Dependency
213213
{
@@ -237,7 +237,7 @@ group dependency by dependency.Id into dependenciesById
237237

238238
// include frameworks referenced by libraries, but without dependencies..
239239
foreach (var targetFramework in (from item in Contents
240-
where item.GetMetadata(MetadataName.Kind) == PackageItemKind.Lib &&
240+
where PackFolderKind.Lib.Equals(item.GetMetadata(MetadataName.PackFolder), StringComparison.OrdinalIgnoreCase) &&
241241
!"all".Equals(item.GetMetadata(MetadataName.PrivateAssets), StringComparison.OrdinalIgnoreCase)
242242
select item.GetNuGetTargetFramework()))
243243
if (!definedDependencyGroups.ContainsKey(targetFramework.GetFrameworkString()))
@@ -283,10 +283,8 @@ void AddFiles(Manifest manifest)
283283
var md5 = new Lazy<HashAlgorithm>(() => MD5.Create());
284284
string hash(ITaskItem item)
285285
{
286-
using (var file = File.OpenRead(item.GetMetadata("FullPath")))
287-
{
288-
return string.Concat(md5.Value.ComputeHash(file).Select(x => x.ToString("x2")));
289-
}
286+
using var file = File.OpenRead(item.GetMetadata("FullPath"));
287+
return string.Concat(md5.Value.ComputeHash(file).Select(x => x.ToString("x2")));
290288
}
291289

292290
// Last remaining attempt at de-duplication is costly, but by now, we should
@@ -341,7 +339,7 @@ string hash(ITaskItem item)
341339
void AddFrameworkAssemblies(Manifest manifest)
342340
{
343341
var frameworkReferences = (from item in Contents
344-
where item.GetMetadata(MetadataName.Kind) == PackageItemKind.FrameworkReference
342+
where item.GetMetadata(MetadataName.PackFolder) == PackFolderKind.FrameworkReference
345343
select new FrameworkAssemblyReference
346344
(
347345
item.ItemSpec,

src/NuGetizer.Tasks/MetadataName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class MetadataName
44
{
55
public const string FileSource = "FullPath";
66

7-
public const string Kind = nameof(Kind);
7+
public const string PackFolder = nameof(PackFolder);
88

99
public const string Version = nameof(Version);
1010

src/NuGetizer.Tasks/NuGetizer.Compatibility.props

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@ Copyright (c) .NET Foundation. All rights reserved.
1414
-->
1515
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1616

17-
<PropertyGroup>
17+
<PropertyGroup Label="SDK Pack Compat">
1818
<PackOnBuild Condition="'$(GeneratePackageOnBuild)' == 'true'">true</PackOnBuild>
19-
<BuildOutputKind Condition="'$(IsTool)' == 'true'">tool</BuildOutputKind>
20-
<BuildOutputKind Condition="'$(BuildOutputTargetFolder)' != ''">$(BuildOutputTargetFolder)</BuildOutputKind>
19+
<PackFolder Condition="'$(IsTool)' == 'true'">tool</PackFolder>
20+
<PackFolder Condition="'$(BuildOutputTargetFolder)' != ''">$(BuildOutputTargetFolder)</PackFolder>
2121
<PackSymbols Condition="'$(PackSymbols)' == '' and '$(IncludeSymbols)' != ''">$(IncludeSymbols)</PackSymbols>
2222
<PackContent Condition="'$(PackContent)' == '' and '$(IncludeContentInPack)' != ''">$(IncludeContentInPack)</PackContent>
2323
<PackCompile Condition="'$(PackCompile)' == '' and '$(IncludeSource)' != ''">$(IncludeSource)</PackCompile>
2424
<PackBuildOutput Condition="'$(PackBuildOutput)' == '' and '$(IncludeBuildOutput)' != ''">$(IncludeBuildOutput)</PackBuildOutput>
2525
<Description Condition="'$(Description)' == '' and '$(PackageDescription)' != ''">$(PackageDescription)</Description>
2626
</PropertyGroup>
2727

28+
<PropertyGroup Label="Legacy NuGetizer Compat">
29+
<PackFolder Condition="'$(PackFolder)' == '' and '$(BuildOutputKind)' != ''">$(BuildOutputKind)</PackFolder>
30+
<PackFolder Condition="'$(PackFolder)' == '' and '$(PrimaryOutputKind)' != ''">$(PrimaryOutputKind)</PackFolder>
31+
32+
<PackContent Condition="'$(PackContent)' == '' and '$(IncludeContentInPackage)' != ''">$(IncludeContentInPackage)</PackContent>
33+
<PackNone Condition="'$(PackNone)' == '' and '$(IncludeNoneInPackage)' != ''">$(IncludeNoneInPackage)</PackNone>
34+
<PackBuildOutput Condition="'$(PackBuildOutput)' == '' and '$(IncludeOutputsInPackage)' != ''">$(IncludeOutputsInPackage)</PackBuildOutput>
35+
<PackSymbols Condition="'$(PackSymbols)' == '' and '$(IncludeSymbolsInPackage)' != ''">$(IncludeSymbolsInPackage)</PackSymbols>
36+
<PackFrameworkReferences Condition="'$(PackFrameworkReferences)' == '' and '$(IncludeFrameworkReferencesInPackage)' != ''">$(IncludeFrameworkReferencesInPackage)</PackFrameworkReferences>
37+
</PropertyGroup>
38+
2839
</Project>

0 commit comments

Comments
 (0)