diff --git a/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj new file mode 100644 index 000000000..9223824fb --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj @@ -0,0 +1,23 @@ + + + + Exe + netcoreapp1.0 + + + + + + + + + + + + + + 1.0.0 + + + + diff --git a/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/Program.cs b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/Program.cs new file mode 100644 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ToolPathCalculator.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ToolPathCalculator.cs index 770e3e579..3300c4ac6 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ToolPathCalculator.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ToolPathCalculator.cs @@ -75,6 +75,11 @@ namespace Microsoft.DotNet.Cli.Utils var availableVersions = new List(); var toolBase = GetBaseToolPath(packageId); + if (!Directory.Exists(toolBase)) + { + return new NuGetVersion[0]; + } + var versionDirectories = Directory.EnumerateDirectories(toolBase); foreach (var versionDirectory in versionDirectories) @@ -94,4 +99,4 @@ namespace Microsoft.DotNet.Cli.Utils } } -} \ No newline at end of file +} diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index a6542bb5d..0906063d2 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -124,6 +124,20 @@ namespace Microsoft.DotNet.Tests .And.Pass(); } + [Fact] + public void ItShowsErrorWhenToolIsNotRestored() + { + var testInstance = TestAssets.Get("NonRestoredTestProjects", "AppWithNonExistingToolDependency") + .CreateInstance() + .WithSourceFiles(); + + new TestCommand("dotnet") + .WithWorkingDirectory(testInstance.Root) + .ExecuteWithCapturedOutput("nonexistingtool") + .Should().Fail() + .And.HaveStdErrContaining("Version for package `dotnet-nonexistingtool` could not be resolved."); + } + // need conditional theories so we can skip on non-Windows //[Theory(Skip="https://github.com/dotnet/cli/issues/4514")] //[MemberData("DependencyToolArguments")]