Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH2478: Add additional dotnet restore arguments #2479

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,77 @@ public void Should_Add_Host_Arguments()
// Then
Assert.Equal("--diagnostics restore", result.Args);
}

[Fact]
public void Should_Add_Interactive()
{
// Given
var fixture = new DotNetCoreRestorerFixture();
fixture.Settings.Interactive = true;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --interactive", result.Args);
}

[Fact]
public void Should_Add_UseLockFile()
{
// Given
var fixture = new DotNetCoreRestorerFixture();
fixture.Settings.UseLockFile = true;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --use-lock-file", result.Args);
}

[Fact]
public void Should_Add_LockedMode()
{
// Given
var fixture = new DotNetCoreRestorerFixture();
fixture.Settings.LockedMode = true;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --locked-mode", result.Args);
}

[Fact]
public void Should_Add_LockFilePath()
{
// Given
var fixture = new DotNetCoreRestorerFixture();
const string lockfile = @"mypackages.lock.json";
fixture.Settings.LockFilePath = lockfile;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --lock-file-path ""/Working/{lockfile}""", result.Args);
}
devlead marked this conversation as resolved.
Show resolved Hide resolved

[Fact]
public void Should_Add_ForceEvaluate()
{
// Given
var fixture = new DotNetCoreRestorerFixture();
fixture.Settings.ForceEvaluate = true;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --force-evaluate", result.Args);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,53 @@ public sealed class DotNetCoreRestoreSettings : DotNetCoreSettings
/// </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>
Expand Down
30 changes: 30 additions & 0 deletions src/Cake.Common/Tools/DotNetCore/Restore/DotNetCoreRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ private ProcessArgumentBuilder GetArguments(string root, DotNetCoreRestoreSettin
builder.Append("--force");
}

// Interactive
if (settings.Interactive)
{
builder.Append("--interactive");
}

// Use lock file
if (settings.UseLockFile)
{
builder.Append("--use-lock-file");
}

// Locked mode
if (settings.LockedMode)
{
builder.Append("--locked-mode");
}

// Lock file path
if (settings.LockFilePath != null)
{
builder.AppendSwitchQuoted("--lock-file-path", " ", settings.LockFilePath.MakeAbsolute(_environment).FullPath);
}

// force evaluate
if (settings.ForceEvaluate)
{
builder.Append("--force-evaluate");
}

if (settings.MSBuildSettings != null)
{
builder.AppendMSBuildSettings(settings.MSBuildSettings, _environment);
Expand Down