Changing the rules on when to use the CLI's BuildRid.
Use the CLI's BuildRid when the current machine is not supported by the shared framework.
This commit is contained in:
parent
ce6c29676d
commit
283bf7139e
3 changed files with 70 additions and 9 deletions
|
@ -10,17 +10,22 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
{
|
||||
public static IEnumerable<string> InferCurrentRuntimeIdentifiers()
|
||||
{
|
||||
// On non-Windows machines, the CLI may be used on a newer version of a supported OS
|
||||
// and the current RID may not be available in the runtime.* NuGet packages, yet.
|
||||
// so fallback to the RID that was used to build the CLI - which will have the correct
|
||||
// runtime.* NuGet packages available.
|
||||
IEnumerable<string> fallbackIdentifiers = null;
|
||||
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
|
||||
|
||||
// If the machine's RID isn't supported by the shared framework (i.e. the CLI
|
||||
// is being used on a newer version of an OS), add the RID that the CLI was built
|
||||
// with as a fallback. The RID the CLI was built with will have the correct
|
||||
// runtime.* NuGet packages available.
|
||||
// For example, when a user is using osx.10.12, but we only support osx.10.10 and
|
||||
// osx.10.11, the project.json "runtimes" section cannot contain osx.10.12, since
|
||||
// that RID isn't contained in the runtime graph - users will get a restore error.
|
||||
FrameworkDependencyFile fxDepsFile = new FrameworkDependencyFile();
|
||||
if (!fxDepsFile.IsCurrentRuntimeSupported())
|
||||
{
|
||||
string buildRid = DotnetFiles.VersionFileObject.BuildRid;
|
||||
if (!string.IsNullOrEmpty(buildRid))
|
||||
{
|
||||
fallbackIdentifiers = new string[] { DotnetFiles.VersionFileObject.BuildRid };
|
||||
fallbackIdentifiers = new string[] { buildRid };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
45
src/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs
Normal file
45
src/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the .deps.json file in the shared framework
|
||||
/// that the CLI is running against.
|
||||
/// </summary>
|
||||
internal class FrameworkDependencyFile
|
||||
{
|
||||
private readonly string _depsFilePath;
|
||||
|
||||
public FrameworkDependencyFile()
|
||||
{
|
||||
_depsFilePath = Muxer.GetDataFromAppDomain("FX_DEPS_FILE");
|
||||
}
|
||||
|
||||
public bool IsCurrentRuntimeSupported()
|
||||
{
|
||||
return IsRuntimeSupported(RuntimeEnvironment.GetRuntimeIdentifier());
|
||||
}
|
||||
|
||||
public bool IsRuntimeSupported(string runtimeIdentifier)
|
||||
{
|
||||
DependencyContext fxDependencyContext = CreateDependencyContext();
|
||||
|
||||
return fxDependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier);
|
||||
}
|
||||
|
||||
private DependencyContext CreateDependencyContext()
|
||||
{
|
||||
using (Stream depsFileStream = File.OpenRead(_depsFilePath))
|
||||
using (DependencyContextJsonReader reader = new DependencyContextJsonReader())
|
||||
{
|
||||
return reader.Read(depsFileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -220,9 +220,7 @@ namespace Microsoft.DotNet.Cli
|
|||
Reporter.Output.WriteLine($" OS Name: {RuntimeEnvironment.OperatingSystem}");
|
||||
Reporter.Output.WriteLine($" OS Version: {RuntimeEnvironment.OperatingSystemVersion}");
|
||||
Reporter.Output.WriteLine($" OS Platform: {RuntimeEnvironment.OperatingSystemPlatform}");
|
||||
|
||||
// report the BuildRid instead of the current RID, so the user knows which RID they should put in their "runtimes" section.
|
||||
Reporter.Output.WriteLine($" RID: {versionFile.BuildRid ?? RuntimeEnvironment.GetRuntimeIdentifier()}");
|
||||
Reporter.Output.WriteLine($" RID: {GetDisplayRid(versionFile)}");
|
||||
}
|
||||
|
||||
private static bool IsArg(string candidate, string longName)
|
||||
|
@ -234,5 +232,18 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
return (shortName != null && candidate.Equals("-" + shortName)) || (longName != null && candidate.Equals("--" + longName));
|
||||
}
|
||||
|
||||
private static string GetDisplayRid(DotnetVersionFile versionFile)
|
||||
{
|
||||
FrameworkDependencyFile fxDepsFile = new FrameworkDependencyFile();
|
||||
|
||||
string currentRid = RuntimeEnvironment.GetRuntimeIdentifier();
|
||||
|
||||
// if the current RID isn't supported by the shared framework, display the RID the CLI was
|
||||
// built with instead, so the user knows which RID they should put in their "runtimes" section.
|
||||
return fxDepsFile.IsRuntimeSupported(currentRid) ?
|
||||
currentRid :
|
||||
versionFile.BuildRid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue