Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
using Cake.Common.Tools.DotNet.Clean;
using Cake.Common.Tools.DotNet.Execute;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
using Cake.Common.Tools.DotNet.Tool;
using Cake.Common.Tools.DotNetCore.Clean;
using Cake.Common.Tools.DotNetCore.Execute;
using Cake.Common.Tools.DotNetCore.MSBuild;
using Cake.Common.Tools.DotNetCore.Restore;
using Cake.Common.Tools.DotNetCore.Run;
using Cake.Common.Tools.DotNetCore.Tool;
using Cake.Core;
Expand Down Expand Up @@ -110,6 +112,109 @@ public static void DotNetExecute(this ICakeContext context, FilePath assemblyPat
executor.Execute(assemblyPath, arguments, settings);
}

/// <summary>
/// Restore all NuGet Packages.
/// </summary>
/// <param name="context">The context.</param>
/// <example>
/// <code>
/// DotNetRestore();
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Restore")]
public static void DotNetRestore(this ICakeContext context)
{
context.DotNetRestore(null, null);
}

/// <summary>
/// Restore all NuGet Packages in the specified path.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="root">List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.</param>
/// <example>
/// <code>
/// DotNetRestore("./src/*");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Restore")]
public static void DotNetRestore(this ICakeContext context, string root)
{
context.DotNetRestore(root, null);
}

/// <summary>
/// Restore all NuGet Packages with the settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetRestoreSettings
/// {
/// Sources = new[] {"https://www.example.com/nugetfeed", "https://www.example.com/nugetfeed2"},
/// FallbackSources = new[] {"https://www.example.com/fallbacknugetfeed"},
/// PackagesDirectory = "./packages",
/// Verbosity = Information,
/// DisableParallel = true,
/// InferRuntimes = new[] {"runtime1", "runtime2"}
/// };
///
/// DotNetRestore(settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Restore")]
public static void DotNetRestore(this ICakeContext context, DotNetRestoreSettings settings)
{
context.DotNetRestore(null, settings);
}

/// <summary>
/// Restore all NuGet Packages in the specified path with settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="root">List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetRestoreSettings
/// {
/// Sources = new[] {"https://www.example.com/nugetfeed", "https://www.example.com/nugetfeed2"},
/// FallbackSources = new[] {"https://www.example.com/fallbacknugetfeed"},
/// PackagesDirectory = "./packages",
/// Verbosity = Information,
/// DisableParallel = true,
/// InferRuntimes = new[] {"runtime1", "runtime2"}
/// };
///
/// DotNetRestore("./src/*", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Restore")]
public static void DotNetRestore(this ICakeContext context, string root, DotNetRestoreSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

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

var restorer = new DotNetCoreRestorer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log);
restorer.Restore(root, settings);
}

/// <summary>
/// Cleans a project's output.
/// </summary>
Expand Down
118 changes: 118 additions & 0 deletions src/Cake.Common/Tools/DotNet/Restore/DotNetRestoreSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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.Restore;
using Cake.Core.IO;

namespace Cake.Common.Tools.DotNet.Restore
{
/// <summary>
/// Contains settings used by <see cref="DotNetCoreRestoreSettings" />.
/// </summary>
public class DotNetRestoreSettings : DotNetCoreSettings
{
/// <summary>
/// Gets or sets the specified NuGet package sources to use during the restore.
/// </summary>
public ICollection<string> Sources { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the NuGet configuration file to use.
/// </summary>
public FilePath ConfigFile { get; set; }

/// <summary>
/// Gets or sets the directory to install packages in.
/// </summary>
public DirectoryPath PackagesDirectory { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to do not cache packages and http requests.
/// </summary>
public bool NoCache { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to disable restoring multiple projects in parallel.
/// </summary>
public bool DisableParallel { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to only warning failed sources if there are packages meeting version requirement.
/// </summary>
public bool IgnoreFailedSources { get; set; }

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

/// <summary>
/// Gets or sets a value indicating whether to ignore project to project references and restore only the root project.
/// </summary>
public bool NoDependencies { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to force all dependencies to be resolved even if the last restore was successful.
/// This is equivalent to deleting the project.assets.json file.
///
/// Note: This flag was introduced with the .NET Core 2.x release.
/// </summary>
public bool Force { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to stop and wait for user input or action (for example to complete authentication).
/// </summary>
/// <remarks>
/// Supported by .NET SDK version 2.1.400 and above.
/// </remarks>
public bool Interactive { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable project lock file to be generated and used with restore.
/// </summary>
/// <remarks>
/// Supported by .NET SDK version 2.1.500 and above.
/// </remarks>
public bool UseLockFile { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to not allow updating project lock file.
/// </summary>
/// <remarks>
/// When set to true, restore will fail if the lock file is out of sync.
/// Useful for CI builds when you do not want the build to continue if the package closure has changed than what is present in the lock file.
/// <para>
/// Supported by .NET SDK version 2.1.500 and above.
/// </para>
/// </remarks>
public bool LockedMode { get; set; }

/// <summary>
/// Gets or sets a value indicating output location where project lock file is written.
/// </summary>
/// <remarks>
/// If not set, 'dotnet restore' defaults to 'PROJECT_ROOT\packages.lock.json'.
/// <para>
/// Supported by .NET SDK version 2.1.500 and above.
/// </para>
/// </remarks>
public FilePath LockFilePath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to force restore to reevaluate all dependencies even if a lock file already exists.
/// </summary>
/// <remarks>
/// Supported by .NET SDK version 2.1.500 and above.
/// </remarks>
public bool ForceEvaluate { get; set; }

/// <summary>
/// Gets or sets additional arguments to be passed to MSBuild.
/// </summary>
public DotNetCoreMSBuildSettings MSBuildSettings { get; set; }
}
}
28 changes: 13 additions & 15 deletions src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Cake.Common.Tools.DotNet.Clean;
using Cake.Common.Tools.DotNet.Execute;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Run;
using Cake.Common.Tools.DotNet.Tool;
using Cake.Common.Tools.DotNetCore.Build;
Expand Down Expand Up @@ -112,6 +113,7 @@ public static void DotNetCoreExecute(this ICakeContext context, FilePath assembl
}

/// <summary>
/// [deprecated] DotNetCoreRestore is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetRestore(ICakeContext)" /> instead.
/// Restore all NuGet Packages.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -123,12 +125,14 @@ public static void DotNetCoreExecute(this ICakeContext context, FilePath assembl
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Restore")]
[Obsolete("DotNetCoreRestore is obsolete and will be removed in a future release. Use DotNetRestore instead.")]
public static void DotNetCoreRestore(this ICakeContext context)
{
context.DotNetCoreRestore(null, null);
context.DotNetRestore();
}

/// <summary>
/// [deprecated] DotNetCoreRestore is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetRestore(ICakeContext, string)" /> instead.
/// Restore all NuGet Packages in the specified path.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -141,12 +145,14 @@ public static void DotNetCoreRestore(this ICakeContext context)
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Restore")]
[Obsolete("DotNetCoreRestore is obsolete and will be removed in a future release. Use DotNetRestore instead.")]
public static void DotNetCoreRestore(this ICakeContext context, string root)
{
context.DotNetCoreRestore(root, null);
context.DotNetRestore(root);
}

/// <summary>
/// [deprecated] DotNetCoreRestore is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetRestore(ICakeContext, DotNetRestoreSettings)" /> instead.
/// Restore all NuGet Packages with the settings.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -169,12 +175,14 @@ public static void DotNetCoreRestore(this ICakeContext context, string root)
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Restore")]
[Obsolete("DotNetCoreRestore is obsolete and will be removed in a future release. Use DotNetRestore instead.")]
public static void DotNetCoreRestore(this ICakeContext context, DotNetCoreRestoreSettings settings)
{
context.DotNetCoreRestore(null, settings);
context.DotNetRestore(settings);
}

/// <summary>
/// [deprecated] DotNetCoreRestore is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetRestore(ICakeContext, string, DotNetRestoreSettings)" /> instead.
/// Restore all NuGet Packages in the specified path with settings.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -198,20 +206,10 @@ public static void DotNetCoreRestore(this ICakeContext context, DotNetCoreRestor
[CakeMethodAlias]
[CakeAliasCategory("Restore")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.Restore")]
[Obsolete("DotNetCoreRestore is obsolete and will be removed in a future release. Use DotNetRestore instead.")]
public static void DotNetCoreRestore(this ICakeContext context, string root, DotNetCoreRestoreSettings settings)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

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

var restorer = new DotNetCoreRestorer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log);
restorer.Restore(root, settings);
context.DotNetRestore(root, settings);
}

/// <summary>
Expand Down
Loading