Addressing comments by adding a test covering the case where the tool assemblies are not found.
This commit is contained in:
parent
a4300cc069
commit
b2116cd2e1
3 changed files with 62 additions and 11 deletions
|
@ -98,7 +98,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
LockFileTargetLibrary toolLibrary,
|
||||
LockFileItem runtimeAssembly)
|
||||
{
|
||||
|
||||
var packageFoldersCount = packageFolders.Count();
|
||||
var userPackageFolder = packageFoldersCount == 1 ? string.Empty : packageFolders.First();
|
||||
var fallbackPackageFolders = packageFoldersCount > 1 ? packageFolders.Skip(1) : packageFolders;
|
||||
|
@ -106,6 +105,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
var packageDirectory = new FallbackPackagePathResolver(userPackageFolder, fallbackPackageFolders)
|
||||
.GetPackageDirectory(toolLibrary.Name, toolLibrary.Version);
|
||||
|
||||
if (packageDirectory == null)
|
||||
{
|
||||
throw new GracefulException(string.Format(
|
||||
LocalizableStrings.CommandAssembliesNotFound,
|
||||
toolLibrary.Name));
|
||||
}
|
||||
|
||||
var filePath = Path.Combine(
|
||||
packageDirectory,
|
||||
PathUtility.GetPathWithDirectorySeparator(runtimeAssembly.Path));
|
||||
|
|
|
@ -71,6 +71,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
public const string NoExecutableFoundMatchingCommand = "No executable found matching command \"{0}\"";
|
||||
|
||||
public const string CommandAssembliesNotFound = "The command executable for \"{0}\" was not found. The project may not have been restored or restore failed - run `dotnet restore`";
|
||||
|
||||
public const string WaitingForDebuggerToAttach = "Waiting for debugger to attach. Press ENTER to continue";
|
||||
|
||||
public const string ProcessId = "Process ID: {0}";
|
||||
|
|
|
@ -348,16 +348,7 @@ namespace Microsoft.DotNet.Tests
|
|||
|
||||
PopulateFallbackFolder(testProjectDirectory, fallbackFolder);
|
||||
|
||||
var nugetConfig = testInstance.Root.GetFile("NuGet.Config").FullName;
|
||||
File.WriteAllText(
|
||||
nugetConfig,
|
||||
$@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<configuration>
|
||||
<fallbackPackageFolders>
|
||||
<add key=""MachineWide"" value=""{fallbackFolder}""/>
|
||||
</fallbackPackageFolders>
|
||||
</configuration>
|
||||
");
|
||||
var nugetConfig = UseNuGetConfigWithFallbackFolder(testInstance, fallbackFolder);
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
|
@ -386,6 +377,42 @@ namespace Microsoft.DotNet.Tests
|
|||
"dotnet-fallbackfoldertool.dll"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItXXXWhenTheToolDllIsNotFound()
|
||||
{
|
||||
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||
|
||||
var testInstance = TestAssets.Get("AppWithFallbackFolderToolDependency")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles();
|
||||
var testProjectDirectory = testInstance.Root.FullName;
|
||||
var fallbackFolder = Path.Combine(testProjectDirectory, "fallbackFolder");
|
||||
|
||||
PopulateFallbackFolder(testProjectDirectory, fallbackFolder);
|
||||
|
||||
var nugetConfig = UseNuGetConfigWithFallbackFolder(testInstance, fallbackFolder);
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute($"--configfile {nugetConfig}")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
Directory.Delete(Path.Combine(fallbackFolder, "dotnet-fallbackfoldertool"), true);
|
||||
|
||||
var commandResolverArguments = new CommandResolverArguments()
|
||||
{
|
||||
CommandName = "dotnet-fallbackfoldertool",
|
||||
CommandArguments = null,
|
||||
ProjectDirectory = testProjectDirectory
|
||||
};
|
||||
|
||||
Action action = () => projectToolsCommandResolver.Resolve(commandResolverArguments);
|
||||
|
||||
action.ShouldThrow<GracefulException>().WithMessage(
|
||||
"The command executable for \"dotnet-fallbackfoldertool\" was not found. The project may not have been restored or restore failed - run `dotnet restore`");
|
||||
}
|
||||
|
||||
private void PopulateFallbackFolder(string testProjectDirectory, string fallbackFolder)
|
||||
{
|
||||
new RestoreCommand()
|
||||
|
@ -397,6 +424,22 @@ namespace Microsoft.DotNet.Tests
|
|||
Directory.Delete(Path.Combine(fallbackFolder, ".tools"), true);
|
||||
}
|
||||
|
||||
private string UseNuGetConfigWithFallbackFolder(TestAssetInstance testInstance, string fallbackFolder)
|
||||
{
|
||||
var nugetConfig = testInstance.Root.GetFile("NuGet.Config").FullName;
|
||||
File.WriteAllText(
|
||||
nugetConfig,
|
||||
$@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<configuration>
|
||||
<fallbackPackageFolders>
|
||||
<add key=""MachineWide"" value=""{fallbackFolder}""/>
|
||||
</fallbackPackageFolders>
|
||||
</configuration>
|
||||
");
|
||||
|
||||
return nugetConfig;
|
||||
}
|
||||
|
||||
private ProjectToolsCommandResolver SetupProjectToolsCommandResolver()
|
||||
{
|
||||
Environment.SetEnvironmentVariable(
|
||||
|
|
Loading…
Reference in a new issue