Clean up tool restore framework fallback logic so there aren't multiple call sites to GetToolLockFile
This commit is contained in:
parent
8b13b3e579
commit
10dd67baa8
1 changed files with 30 additions and 31 deletions
|
@ -134,40 +134,39 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
ProjectToolsCommandResolverName,
|
||||
string.Join(Environment.NewLine, possiblePackageRoots.Select((p) => $"- {p}"))));
|
||||
|
||||
var toolPackageFramework = project.DotnetCliToolTargetFramework;
|
||||
|
||||
var toolLockFile = GetToolLockFile(
|
||||
toolLibraryRange,
|
||||
toolPackageFramework,
|
||||
possiblePackageRoots);
|
||||
|
||||
List<NuGetFramework> toolFrameworksToCheck = new List<NuGetFramework>();
|
||||
toolFrameworksToCheck.Add(project.DotnetCliToolTargetFramework);
|
||||
|
||||
// NuGet restore in Visual Studio may restore for netcoreapp1.0. So if that happens, fall back to
|
||||
// looking for a netcoreapp1.0 or netcoreapp1.1 tool restore.
|
||||
if (project.DotnetCliToolTargetFramework.Framework == FrameworkConstants.FrameworkIdentifiers.NetCoreApp &&
|
||||
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 (toolPackageFramework.Framework == FrameworkConstants.FrameworkIdentifiers.NetCoreApp &&
|
||||
toolPackageFramework.Version >= new Version(2, 0, 0))
|
||||
{
|
||||
foreach (var fallbackFramework in new [] { "netcoreapp1.1", "netcoreapp1.0"})
|
||||
{
|
||||
toolPackageFramework = NuGetFramework.Parse(fallbackFramework);
|
||||
toolLockFile = GetToolLockFile(
|
||||
toolLibraryRange,
|
||||
toolPackageFramework,
|
||||
possiblePackageRoots);
|
||||
|
||||
if (toolLockFile != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toolLockFile == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reporter.Verbose.WriteLine(string.Format(
|
||||
|
@ -176,7 +175,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
toolLockFile.Path));
|
||||
|
||||
var toolLibrary = toolLockFile.Targets
|
||||
.FirstOrDefault(t => toolPackageFramework == t.TargetFramework)
|
||||
.FirstOrDefault(t => toolTargetFramework == t.TargetFramework)
|
||||
?.Libraries.FirstOrDefault(
|
||||
l => StringComparer.OrdinalIgnoreCase.Equals(l.Name, toolLibraryRange.Name));
|
||||
if (toolLibrary == null)
|
||||
|
@ -192,7 +191,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
var depsFilePath = GetToolDepsFilePath(
|
||||
toolLibraryRange,
|
||||
toolPackageFramework,
|
||||
toolTargetFramework,
|
||||
toolLockFile,
|
||||
depsFileRoot,
|
||||
project.ToolDepsJsonGeneratorProject);
|
||||
|
|
Loading…
Reference in a new issue