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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class ReferenceAddCommand : CommandBase<ReferenceAddCommandDefin
public ReferenceAddCommand(ParseResult parseResult)
: base(parseResult)
{
_fileOrDirectory = Definition.GetFileOrDirectory(parseResult);
_fileOrDirectory = Definition.GetFileOrDirectory(parseResult) ?? Directory.GetCurrentDirectory();
}

public override int Execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class ReferenceRemoveCommand : CommandBase<ReferenceRemoveComman
public ReferenceRemoveCommand(ParseResult parseResult)
: base(parseResult)
{
_fileOrDirectory = Definition.GetFileOrDirectory(parseResult);
_fileOrDirectory = Definition.GetFileOrDirectory(parseResult) ?? Directory.GetCurrentDirectory();
_arguments = parseResult.GetValue(Definition.ProjectPathArgument).ToList().AsReadOnly();

if (_arguments.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,22 @@ public void WhenDirectoryContainingProjectIsGivenReferenceIsAdded()
result.StdErr.Should().BeEmpty();
}

[Fact]
public void WhenNoProjectIsSpecifiedItUsesCurrentDirectory()
{
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);

// Reproduces: dotnet reference add ../ValidRef/ValidRef.csproj
// where the current directory contains a project (no --project argument needed)
var result = new DotnetCommand(Log, "reference", "add")
.WithWorkingDirectory(lib.Path)
.Execute(setup.ValidRefCsprojPath);

result.Should().Pass();
result.StdErr.Should().BeEmpty();
}

[Fact]
public void WhenDirectoryContainsNoProjectsItCancelsWholeOperation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,22 @@ public void WhenDirectoryContainsMultipleProjectsItCancelsWholeOperation()
result.StdOut.Should().BeVisuallyEquivalentToIfNotLocalized("");
result.StdErr.Should().Be(string.Format(CliStrings.MoreThanOneProjectInDirectory, Path.Combine(setup.TestRoot, reference)));
}

[Fact]
public void WhenNoProjectIsSpecifiedItUsesCurrentDirectory()
{
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
var libref = AddLibRef(setup, lib);

// Reproduces: dotnet reference remove ../Lib/Lib.csproj
// where the current directory contains a project (no --project argument needed)
var result = new DotnetCommand(Log, "reference", "remove")
.WithWorkingDirectory(lib.Path)
.Execute(libref.CsProjPath);

result.Should().Pass();
result.StdErr.Should().BeEmpty();
}
}
}
Loading