Merge pull request #6525 from dsplaisted/tool-tfm-fallback
Fall back to tools restored for .NET Core 1.x if they haven't been restored for .NET Core 2.0
This commit is contained in:
commit
75af8b479e
2 changed files with 84 additions and 8 deletions
|
@ -134,12 +134,35 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
ProjectToolsCommandResolverName,
|
ProjectToolsCommandResolverName,
|
||||||
string.Join(Environment.NewLine, possiblePackageRoots.Select((p) => $"- {p}"))));
|
string.Join(Environment.NewLine, possiblePackageRoots.Select((p) => $"- {p}"))));
|
||||||
|
|
||||||
var toolPackageFramework = project.DotnetCliToolTargetFramework;
|
List<NuGetFramework> toolFrameworksToCheck = new List<NuGetFramework>();
|
||||||
|
toolFrameworksToCheck.Add(project.DotnetCliToolTargetFramework);
|
||||||
|
|
||||||
var toolLockFile = GetToolLockFile(
|
// NuGet restore in Visual Studio may restore for netcoreapp1.0. So if that happens, fall back to
|
||||||
toolLibraryRange,
|
// looking for a netcoreapp1.0 or netcoreapp1.1 tool restore.
|
||||||
toolPackageFramework,
|
if (project.DotnetCliToolTargetFramework.Framework == FrameworkConstants.FrameworkIdentifiers.NetCoreApp &&
|
||||||
possiblePackageRoots);
|
project.DotnetCliToolTargetFramework.Version >= new Version(2, 0, 0))
|
||||||
|
{
|
||||||
|
toolFrameworksToCheck.Add(NuGetFramework.Parse("netcoreapp1.1"));
|
||||||
|
toolFrameworksToCheck.Add(NuGetFramework.Parse("netcoreapp1.0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LockFile toolLockFile = null;
|
||||||
|
NuGetFramework toolTargetFramework = null; ;
|
||||||
|
|
||||||
|
foreach (var toolFramework in toolFrameworksToCheck)
|
||||||
|
{
|
||||||
|
toolLockFile = GetToolLockFile(
|
||||||
|
toolLibraryRange,
|
||||||
|
toolFramework,
|
||||||
|
possiblePackageRoots);
|
||||||
|
|
||||||
|
if (toolLockFile != null)
|
||||||
|
{
|
||||||
|
toolTargetFramework = toolFramework;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (toolLockFile == null)
|
if (toolLockFile == null)
|
||||||
{
|
{
|
||||||
|
@ -152,7 +175,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
toolLockFile.Path));
|
toolLockFile.Path));
|
||||||
|
|
||||||
var toolLibrary = toolLockFile.Targets
|
var toolLibrary = toolLockFile.Targets
|
||||||
.FirstOrDefault(t => toolPackageFramework == t.TargetFramework)
|
.FirstOrDefault(t => toolTargetFramework == t.TargetFramework)
|
||||||
?.Libraries.FirstOrDefault(
|
?.Libraries.FirstOrDefault(
|
||||||
l => StringComparer.OrdinalIgnoreCase.Equals(l.Name, toolLibraryRange.Name));
|
l => StringComparer.OrdinalIgnoreCase.Equals(l.Name, toolLibraryRange.Name));
|
||||||
if (toolLibrary == null)
|
if (toolLibrary == null)
|
||||||
|
@ -168,7 +191,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
var depsFilePath = GetToolDepsFilePath(
|
var depsFilePath = GetToolDepsFilePath(
|
||||||
toolLibraryRange,
|
toolLibraryRange,
|
||||||
toolPackageFramework,
|
toolTargetFramework,
|
||||||
toolLockFile,
|
toolLockFile,
|
||||||
depsFileRoot,
|
depsFileRoot,
|
||||||
project.ToolDepsJsonGeneratorProject);
|
project.ToolDepsJsonGeneratorProject);
|
||||||
|
|
|
@ -16,6 +16,7 @@ using Xunit.Abstractions;
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Build.Evaluation;
|
using Microsoft.Build.Evaluation;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tests
|
namespace Microsoft.DotNet.Tests
|
||||||
{
|
{
|
||||||
|
@ -161,10 +162,62 @@ namespace Microsoft.DotNet.Tests
|
||||||
.Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1");
|
.Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1");
|
||||||
|
|
||||||
result.Should().Pass()
|
result.Should().Pass()
|
||||||
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.1!");
|
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.1!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequiresSpecificFrameworkFact("netcoreapp1.1")]
|
||||||
|
public void IfAToolHasNotBeenRestoredForNetCoreApp2_0ItFallsBackToNetCoreApp1_x()
|
||||||
|
{
|
||||||
|
string toolName = "dotnet-portable-v1";
|
||||||
|
|
||||||
|
var toolFolder = Path.Combine(new RepoDirectoriesProvider().NugetPackages,
|
||||||
|
".tools",
|
||||||
|
toolName);
|
||||||
|
|
||||||
|
// Other tests may have restored the tool for netcoreapp2.0, so delete its tools folder
|
||||||
|
if (Directory.Exists(toolFolder))
|
||||||
|
{
|
||||||
|
Directory.Delete(toolFolder, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testInstance = TestAssets.Get("AppWithToolDependency")
|
||||||
|
.CreateInstance()
|
||||||
|
.WithSourceFiles()
|
||||||
|
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages);
|
||||||
|
|
||||||
|
testInstance = testInstance.WithProjectChanges(project =>
|
||||||
|
{
|
||||||
|
var ns = project.Root.Name.Namespace;
|
||||||
|
|
||||||
|
// Remove reference to tool that won't restore on 1.x
|
||||||
|
project.Descendants(ns + "DotNetCliToolReference")
|
||||||
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-PreferCliRuntime")
|
||||||
|
.Remove();
|
||||||
|
|
||||||
|
var toolReference = project.Descendants(ns + "DotNetCliToolReference")
|
||||||
|
.Where(tr => tr.Attribute("Include").Value == "dotnet-portable")
|
||||||
|
.Single();
|
||||||
|
|
||||||
|
toolReference.Attribute("Include").Value = toolName;
|
||||||
|
|
||||||
|
// Restore tools for .NET Core 1.1
|
||||||
|
project.Root.Element(ns + "PropertyGroup")
|
||||||
|
.Add(new XElement(ns + "DotnetCliToolTargetFramework", "netcoreapp1.1"));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
testInstance = testInstance.WithRestoreFiles();
|
||||||
|
|
||||||
|
var result =
|
||||||
|
new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes)
|
||||||
|
.WithWorkingDirectory(testInstance.Root)
|
||||||
|
.Execute("portable-v1");
|
||||||
|
|
||||||
|
result.Should().Pass()
|
||||||
|
.And.HaveStdOutContaining("I'm running on shared framework version 1.1.1!");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanInvokeToolWhosePackageNameIsDifferentFromDllName()
|
public void CanInvokeToolWhosePackageNameIsDifferentFromDllName()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue