Skip to content

Commit

Permalink
(cake-build#3552) Add DotNetPack alias (synonym to DotNetCorePack)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustoproiete committed Oct 25, 2021
1 parent 6b626d8 commit c281508
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 107 deletions.
56 changes: 56 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Cake.Common.Tools.DotNet.Clean;
using Cake.Common.Tools.DotNet.Execute;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Common.Tools.DotNet.Publish;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
Expand All @@ -21,6 +22,7 @@
using Cake.Common.Tools.DotNetCore.Clean;
using Cake.Common.Tools.DotNetCore.Execute;
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Common.Tools.DotNetCore.Pack;
using Cake.Common.Tools.DotNetCore.Publish;
using Cake.Common.Tools.DotNetCore.Restore;
using Cake.Common.Tools.DotNetCore.Run;
Expand Down Expand Up @@ -557,6 +559,60 @@ public static void DotNetClean(this ICakeContext context, string project, DotNet
cleaner.Clean(project, settings);
}

/// <summary>
/// Package all projects.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The projects path.</param>
/// <example>
/// <code>
/// DotNetPack("./src/*");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pack")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Pack")]
public static void DotNetPack(this ICakeContext context, string project)
{
context.DotNetPack(project, null);
}

/// <summary>
/// Package all projects.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The projects path.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetPackSettings
/// {
/// Configuration = "Release",
/// OutputDirectory = "./artifacts/"
/// };
///
/// DotNetPack("./src/*", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Pack")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Pack")]
public static void DotNetPack(this ICakeContext context, string project, DotNetPackSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (settings is null)
{
settings = new DotNetPackSettings();
}

var packer = new DotNetCorePacker(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
packer.Pack(project, settings);
}

/// <summary>
/// Run all projects.
/// </summary>
Expand Down
106 changes: 106 additions & 0 deletions src/Cake.Common/Tools/DotNet/Pack/DotNetPackSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Common.Tools.DotNetCore.Pack;
using Cake.Core.IO;

namespace Cake.Common.Tools.DotNet.Pack
{
/// <summary>
/// Contains settings used by <see cref="DotNetCorePacker" />.
/// </summary>
public class DotNetPackSettings : DotNetCoreSettings
{
/// <summary>
/// Gets or sets the output directory.
/// </summary>
public DirectoryPath OutputDirectory { get; set; }

/// <summary>
/// Gets or sets the configuration under which to build.
/// </summary>
public string Configuration { get; set; }

/// <summary>
/// Gets or sets the value that defines what `*` should be replaced with in version field in project.json.
/// </summary>
public string VersionSuffix { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not build project before packing.
/// </summary>
public bool NoBuild { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to ignore project to project references and only build the root project.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public bool NoDependencies { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not do implicit NuGet package restore.
/// This makes build faster, but requires restore to be done before build is executed.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public bool NoRestore { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to display the startup banner or the copyright message.
/// </summary>
/// <remarks>
/// Available since .NET Core 3.0 SDK.
/// </remarks>
public bool NoLogo { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to generate the symbols package.
/// </summary>
public bool IncludeSymbols { get; set; }

/// <summary>
/// Gets or sets the symbol package format.
/// </summary>
/// <value>The symbol package format.</value>
public string SymbolPackageFormat { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to includes the source files in the NuGet package.
/// The sources files are included in the src folder within the nupkg.
/// </summary>
public bool IncludeSource { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to set the serviceable flag in the package.
/// </summary>
/// <remarks>
/// For more information, see https://aka.ms/nupkgservicing.
/// </remarks>
public bool Serviceable { get; set; }

/// <summary>
/// Gets or sets the target runtime.
/// </summary>
public string Runtime { get; set; }

/// <summary>
/// Gets or sets the specified NuGet package sources to use during the packing.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public ICollection<string> Sources { get; set; } = new List<string>();

/// <summary>
/// Gets or sets additional arguments to be passed to MSBuild.
/// </summary>
public DotNetCoreMSBuildSettings MSBuildSettings { get; set; }
}
}
20 changes: 7 additions & 13 deletions src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Cake.Common.Tools.DotNet.Clean;
using Cake.Common.Tools.DotNet.Execute;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Common.Tools.DotNet.Publish;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
Expand Down Expand Up @@ -266,6 +267,7 @@ public static void DotNetCoreBuild(this ICakeContext context, string project, Do
}

/// <summary>
/// [deprecated] DotNetCorePack is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetPack(ICakeContext, string)" /> instead.
/// Package all projects.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -278,12 +280,14 @@ public static void DotNetCoreBuild(this ICakeContext context, string project, Do
[CakeMethodAlias]
[CakeAliasCategory("Pack")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Pack")]
[Obsolete("DotNetCorePack is obsolete and will be removed in a future release. Use DotNetPack instead.")]
public static void DotNetCorePack(this ICakeContext context, string project)
{
context.DotNetCorePack(project, null);
context.DotNetPack(project);
}

/// <summary>
/// [deprecated] DotNetCorePack is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetPack(ICakeContext, string, DotNetPackSettings)" /> instead.
/// Package all projects.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -303,20 +307,10 @@ public static void DotNetCorePack(this ICakeContext context, string project)
[CakeMethodAlias]
[CakeAliasCategory("Pack")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Pack")]
[Obsolete("DotNetCorePack is obsolete and will be removed in a future release. Use DotNetPack instead.")]
public static void DotNetCorePack(this ICakeContext context, string project, DotNetCorePackSettings settings)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (settings == null)
{
settings = new DotNetCorePackSettings();
}

var packer = new DotNetCorePacker(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
packer.Pack(project, settings);
context.DotNetPack(project, settings);
}

/// <summary>
Expand Down
93 changes: 2 additions & 91 deletions src/Cake.Common/Tools/DotNetCore/Pack/DotNetCorePackSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Core.IO;
using Cake.Common.Tools.DotNet.Pack;

namespace Cake.Common.Tools.DotNetCore.Pack
{
/// <summary>
/// Contains settings used by <see cref="DotNetCorePacker" />.
/// </summary>
public sealed class DotNetCorePackSettings : DotNetCoreSettings
public sealed class DotNetCorePackSettings : DotNetPackSettings
{
/// <summary>
/// Gets or sets the output directory.
/// </summary>
public DirectoryPath OutputDirectory { get; set; }

/// <summary>
/// Gets or sets the configuration under which to build.
/// </summary>
public string Configuration { get; set; }

/// <summary>
/// Gets or sets the value that defines what `*` should be replaced with in version field in project.json.
/// </summary>
public string VersionSuffix { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not build project before packing.
/// </summary>
public bool NoBuild { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to ignore project to project references and only build the root project.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public bool NoDependencies { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not do implicit NuGet package restore.
/// This makes build faster, but requires restore to be done before build is executed.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public bool NoRestore { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to display the startup banner or the copyright message.
/// </summary>
/// <remarks>
/// Available since .NET Core 3.0 SDK.
/// </remarks>
public bool NoLogo { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to generate the symbols package.
/// </summary>
public bool IncludeSymbols { get; set; }

/// <summary>
/// Gets or sets the symbol package format.
/// </summary>
/// <value>The symbol package format.</value>
public string SymbolPackageFormat { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to includes the source files in the NuGet package.
/// The sources files are included in the src folder within the nupkg.
/// </summary>
public bool IncludeSource { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to set the serviceable flag in the package.
/// </summary>
/// <remarks>
/// For more information, see https://aka.ms/nupkgservicing.
/// </remarks>
public bool Serviceable { get; set; }

/// <summary>
/// Gets or sets the target runtime.
/// </summary>
public string Runtime { get; set; }

/// <summary>
/// Gets or sets the specified NuGet package sources to use during the packing.
/// </summary>
/// <remarks>
/// Requires .NET Core 2.x or newer.
/// </remarks>
public ICollection<string> Sources { get; set; } = new List<string>();

/// <summary>
/// Gets or sets additional arguments to be passed to MSBuild.
/// </summary>
public DotNetCoreMSBuildSettings MSBuildSettings { get; set; }
}
}
7 changes: 4 additions & 3 deletions src/Cake.Common/Tools/DotNetCore/Pack/DotNetCorePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Core;
using Cake.Core.IO;
Expand All @@ -13,7 +14,7 @@ namespace Cake.Common.Tools.DotNetCore.Pack
/// <summary>
/// .NET Core project packer.
/// </summary>
public sealed class DotNetCorePacker : DotNetCoreTool<DotNetCorePackSettings>
public sealed class DotNetCorePacker : DotNetCoreTool<DotNetPackSettings>
{
private readonly ICakeEnvironment _environment;

Expand All @@ -38,7 +39,7 @@ public DotNetCorePacker(
/// </summary>
/// <param name="project">The target file path.</param>
/// <param name="settings">The settings.</param>
public void Pack(string project, DotNetCorePackSettings settings)
public void Pack(string project, DotNetPackSettings settings)
{
if (settings == null)
{
Expand All @@ -48,7 +49,7 @@ public void Pack(string project, DotNetCorePackSettings settings)
RunCommand(settings, GetArguments(project, settings));
}

private ProcessArgumentBuilder GetArguments(string project, DotNetCorePackSettings settings)
private ProcessArgumentBuilder GetArguments(string project, DotNetPackSettings settings)
{
var builder = CreateArgumentBuilder(settings);

Expand Down

0 comments on commit c281508

Please sign in to comment.