Skip to content

Commit

Permalink
Add additional dotnet restore arguments
Browse files Browse the repository at this point in the history
- This implements part of cake-build#2478
  • Loading branch information
flcdrg committed Feb 20, 2019
1 parent 020d6d3 commit 7368cbd
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
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);
}

[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

0 comments on commit 7368cbd

Please sign in to comment.