fix tools when restoring with --packages
This commit is contained in:
parent
2d5e40f3ba
commit
59ae0e2d3d
11 changed files with 197 additions and 13 deletions
|
@ -13,6 +13,9 @@ using Microsoft.DotNet.Tools.Test.Utilities;
|
|||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Microsoft.Build.Construction;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Evaluation;
|
||||
|
||||
namespace Microsoft.DotNet.Tests
|
||||
{
|
||||
|
@ -138,6 +141,52 @@ namespace Microsoft.DotNet.Tests
|
|||
.And.HaveStdErrContaining("Version for package `dotnet-nonexistingtool` could not be resolved.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItRunsToolRestoredToSpecificPackageDir()
|
||||
{
|
||||
var testInstance = TestAssets.Get("NonRestoredTestProjects", "ToolWithRandomPackageName")
|
||||
.CreateInstance()
|
||||
.WithSourceFiles();
|
||||
|
||||
var appWithDepOnToolDir = testInstance.Root.Sub("AppWithDepOnTool");
|
||||
var toolWithRandPkgNameDir = testInstance.Root.Sub("ToolWithRandomPackageName");
|
||||
var pkgsDir = testInstance.Root.CreateSubdirectory("pkgs");
|
||||
|
||||
string randomPackageName = Guid.NewGuid().ToString();
|
||||
|
||||
// TODO: This is a workround for https://github.com/dotnet/cli/issues/5020
|
||||
SetGeneratedPackageName(appWithDepOnToolDir.GetFile("AppWithDepOnTool.csproj"),
|
||||
randomPackageName);
|
||||
|
||||
SetGeneratedPackageName(toolWithRandPkgNameDir.GetFile("ToolWithRandomPackageName.csproj"),
|
||||
randomPackageName);
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(toolWithRandPkgNameDir)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should().Pass()
|
||||
.And.NotHaveStdErr();
|
||||
|
||||
new PackCommand()
|
||||
.WithWorkingDirectory(toolWithRandPkgNameDir)
|
||||
.ExecuteWithCapturedOutput($"-o \"{pkgsDir.FullName}\"")
|
||||
.Should().Pass()
|
||||
.And.NotHaveStdErr();
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(appWithDepOnToolDir)
|
||||
.ExecuteWithCapturedOutput($"--packages \"{pkgsDir.FullName}\"")
|
||||
.Should().Pass()
|
||||
.And.NotHaveStdErr();
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.WithWorkingDirectory(appWithDepOnToolDir)
|
||||
.ExecuteWithCapturedOutput("randompackage")
|
||||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("Hello World from tool!")
|
||||
.And.NotHaveStdErr();
|
||||
}
|
||||
|
||||
// need conditional theories so we can skip on non-Windows
|
||||
//[Theory(Skip="https://github.com/dotnet/cli/issues/4514")]
|
||||
//[MemberData("DependencyToolArguments")]
|
||||
|
@ -294,6 +343,14 @@ namespace Microsoft.DotNet.Tests
|
|||
stopWatch.ElapsedMilliseconds.Should().BeGreaterThan(1000, "Because dotnet should respect the NuGet lock");
|
||||
}
|
||||
|
||||
private void SetGeneratedPackageName(FileInfo project, string packageName)
|
||||
{
|
||||
const string propertyName = "GeneratedPackageId";
|
||||
var p = ProjectRootElement.Open(project.FullName, new ProjectCollection(), true);
|
||||
p.AddProperty(propertyName, packageName);
|
||||
p.Save();
|
||||
}
|
||||
|
||||
class HelloCommand : TestCommand
|
||||
{
|
||||
public HelloCommand()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue