Skip to content

Commit

Permalink
Rename Kind to PackFolder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kzu committed Oct 1, 2020
1 parent 4cb96d4 commit 062349c
Show file tree
Hide file tree
Showing 31 changed files with 373 additions and 316 deletions.
3 changes: 0 additions & 3 deletions NuGetizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CDF1828A-0877-4238-A218-5E4FE219F6CC}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
azure-pipelines.yml = azure-pipelines.yml
.github\workflows\build.yml = .github\workflows\build.yml
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
src\NuGet.Config = src\NuGet.Config
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGetizer.Tasks", "src\NuGetizer.Tasks\NuGetizer.Tasks.csproj", "{57F59BF6-9272-4B66-98A1-334B3FDA5721}"
Expand Down
122 changes: 90 additions & 32 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Import Project="NuGetizer.Tasks\$(OutputPath)NuGetizer.targets" Condition="$(IsPackable) and '$(NuGetize)' == 'true'" />

<PropertyGroup>
<PackageItemKindFile>$(IntermediateOutputPath)PackageItemKind.g$(DefaultLanguageSourceExtension)</PackageItemKindFile>
<PackFolderKindFile>$(IntermediateOutputPath)PackFolderKind.g$(DefaultLanguageSourceExtension)</PackFolderKindFile>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 14 additions & 14 deletions src/NuGetizer.Tasks/AssignPackagePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NuGetizer.Tasks
/// Ensures all files have the PackagePath metadata.
/// If the PackagePath was not explicitly specified,
/// determine one from the project relative path and
/// the TargetFramework and Kind metadata, and set it
/// the TargetFramework and PackFolder metadata, and set it
/// on the projected item.
/// </summary>
public class AssignPackagePath : Task
Expand All @@ -24,14 +24,14 @@ public class AssignPackagePath : Task
public ITaskItem[] Files { get; set; }

[Required]
public ITaskItem[] Kinds { get; set; }
public ITaskItem[] KnownFolders { get; set; }

[Output]
public ITaskItem[] AssignedFiles { get; set; }

public override bool Execute()
{
var kindMap = Kinds.ToDictionary(
var kindMap = KnownFolders.ToDictionary(
kind => kind.ItemSpec,
StringComparer.OrdinalIgnoreCase);

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

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

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

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

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

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

// Special case for contentFiles, since they can also provide a codeLanguage metadata
Expand Down
14 changes: 6 additions & 8 deletions src/NuGetizer.Tasks/CreatePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Manifest Execute(Stream output)
public Manifest CreateManifest()
{
var metadata = new ManifestMetadata();

metadata.Id = Manifest.GetMetadata(nameof(MetadataName.PackageId));

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

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

// Last remaining attempt at de-duplication is costly, but by now, we should
Expand Down Expand Up @@ -341,7 +339,7 @@ string hash(ITaskItem item)
void AddFrameworkAssemblies(Manifest manifest)
{
var frameworkReferences = (from item in Contents
where item.GetMetadata(MetadataName.Kind) == PackageItemKind.FrameworkReference
where item.GetMetadata(MetadataName.PackFolder) == PackFolderKind.FrameworkReference
select new FrameworkAssemblyReference
(
item.ItemSpec,
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetizer.Tasks/MetadataName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class MetadataName
{
public const string FileSource = "FullPath";

public const string Kind = nameof(Kind);
public const string PackFolder = nameof(PackFolder);

public const string Version = nameof(Version);

Expand Down
17 changes: 14 additions & 3 deletions src/NuGetizer.Tasks/NuGetizer.Compatibility.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<PropertyGroup Label="SDK Pack Compat">
<PackOnBuild Condition="'$(GeneratePackageOnBuild)' == 'true'">true</PackOnBuild>
<BuildOutputKind Condition="'$(IsTool)' == 'true'">tool</BuildOutputKind>
<BuildOutputKind Condition="'$(BuildOutputTargetFolder)' != ''">$(BuildOutputTargetFolder)</BuildOutputKind>
<PackFolder Condition="'$(IsTool)' == 'true'">tool</PackFolder>
<PackFolder Condition="'$(BuildOutputTargetFolder)' != ''">$(BuildOutputTargetFolder)</PackFolder>
<PackSymbols Condition="'$(PackSymbols)' == '' and '$(IncludeSymbols)' != ''">$(IncludeSymbols)</PackSymbols>
<PackContent Condition="'$(PackContent)' == '' and '$(IncludeContentInPack)' != ''">$(IncludeContentInPack)</PackContent>
<PackCompile Condition="'$(PackCompile)' == '' and '$(IncludeSource)' != ''">$(IncludeSource)</PackCompile>
<PackBuildOutput Condition="'$(PackBuildOutput)' == '' and '$(IncludeBuildOutput)' != ''">$(IncludeBuildOutput)</PackBuildOutput>
<Description Condition="'$(Description)' == '' and '$(PackageDescription)' != ''">$(PackageDescription)</Description>
</PropertyGroup>

<PropertyGroup Label="Legacy NuGetizer Compat">
<PackFolder Condition="'$(PackFolder)' == '' and '$(BuildOutputKind)' != ''">$(BuildOutputKind)</PackFolder>
<PackFolder Condition="'$(PackFolder)' == '' and '$(PrimaryOutputKind)' != ''">$(PrimaryOutputKind)</PackFolder>

<PackContent Condition="'$(PackContent)' == '' and '$(IncludeContentInPackage)' != ''">$(IncludeContentInPackage)</PackContent>
<PackNone Condition="'$(PackNone)' == '' and '$(IncludeNoneInPackage)' != ''">$(IncludeNoneInPackage)</PackNone>
<PackBuildOutput Condition="'$(PackBuildOutput)' == '' and '$(IncludeOutputsInPackage)' != ''">$(IncludeOutputsInPackage)</PackBuildOutput>
<PackSymbols Condition="'$(PackSymbols)' == '' and '$(IncludeSymbolsInPackage)' != ''">$(IncludeSymbolsInPackage)</PackSymbols>
<PackFrameworkReferences Condition="'$(PackFrameworkReferences)' == '' and '$(IncludeFrameworkReferencesInPackage)' != ''">$(IncludeFrameworkReferencesInPackage)</PackFrameworkReferences>
</PropertyGroup>

</Project>
Loading

0 comments on commit 062349c

Please sign in to comment.