Merge pull request #4281 from dotnet/CapRIDs

Support developing on new versions of a supported OS
This commit is contained in:
Eric Erhardt 2016-10-03 14:08:45 -05:00 committed by GitHub
commit 79b9f3c22a
20 changed files with 205 additions and 49 deletions

View file

@ -262,7 +262,8 @@ namespace Microsoft.DotNet.Cli.Build
// Generate .version file
var version = buildVersion.NuGetVersion;
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
var buildRid = RuntimeEnvironment.GetRuntimeIdentifier();
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}{buildRid}{Environment.NewLine}";
File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content);
if(generateNugetPackagesArchive)

View file

@ -79,7 +79,7 @@ namespace Microsoft.DotNet.Cli.Utils
var projectContext = ProjectContext.Create(
projectRootPath,
framework,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers());
if (projectContext.RuntimeIdentifier == null)
{

View file

@ -140,7 +140,7 @@ namespace Microsoft.DotNet.Cli.Utils
return ProjectContext.Create(
projectRootPath,
framework,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers());
}

View file

@ -19,9 +19,6 @@ namespace Microsoft.DotNet.Cli.Utils
private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
CommandResolutionStrategy.ProjectToolsPackage;
private static readonly string s_currentRuntimeIdentifier = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
private List<string> _allowedCommandExtensions;
private IPackagedCommandSpecFactory _packagedCommandSpecFactory;

View file

@ -12,11 +12,19 @@ namespace Microsoft.DotNet.Cli.Utils
{
private static string SdkRootFolder => Path.Combine(typeof(DotnetFiles).GetTypeInfo().Assembly.Location, "..");
private static Lazy<DotnetVersionFile> s_versionFileObject =
new Lazy<DotnetVersionFile>(() => new DotnetVersionFile(VersionFile));
/// <summary>
/// The CLI ships with a .version file that stores the commit information and CLI version
/// </summary>
public static string VersionFile => Path.GetFullPath(Path.Combine(SdkRootFolder, ".version"));
internal static DotnetVersionFile VersionFileObject
{
get { return s_versionFileObject.Value; }
}
public static string NuGetPackagesArchive =>
Path.GetFullPath(Path.Combine(SdkRootFolder, "nuGetPackagesArchive.lzma"));

View file

@ -0,0 +1,35 @@
// 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.Collections.Generic;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
internal static class DotnetRuntimeIdentifiers
{
public static IEnumerable<string> InferCurrentRuntimeIdentifiers()
{
IEnumerable<string> fallbackIdentifiers = null;
// 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.SupportsCurrentRuntime())
{
string buildRid = DotnetFiles.VersionFileObject.BuildRid;
if (!string.IsNullOrEmpty(buildRid))
{
fallbackIdentifiers = new string[] { buildRid };
}
}
return RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers(fallbackIdentifiers);
}
}
}

View file

@ -0,0 +1,61 @@
// 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.Collections.Generic;
using System.IO;
namespace Microsoft.DotNet.Cli.Utils
{
internal class DotnetVersionFile
{
public bool Exists { get; set; }
public string CommitSha { get; set; }
public string BuildNumber { get; set; }
/// <summary>
/// The runtime identifier (rid) that this CLI was built for.
/// </summary>
/// <remarks>
/// This is different than RuntimeEnvironment.GetRuntimeIdentifier() because the
/// BuildRid is a RID that is guaranteed to exist and works on the current machine. The
/// RuntimeEnvironment.GetRuntimeIdentifier() may be for a new version of the OS that
/// doesn't have full support yet.
/// </remarks>
public string BuildRid { get; set; }
public DotnetVersionFile(string versionFilePath)
{
Exists = File.Exists(versionFilePath);
if (Exists)
{
IEnumerable<string> lines = File.ReadLines(versionFilePath);
int index = 0;
foreach (string line in lines)
{
if (index == 0)
{
CommitSha = line.Substring(0, 10);
}
else if (index == 1)
{
BuildNumber = line;
}
else if (index == 2)
{
BuildRid = line;
}
else
{
break;
}
index++;
}
}
}
}
}

View 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 SupportsCurrentRuntime()
{
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);
}
}
}
}

View file

@ -2,4 +2,5 @@ using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyMetadataAttribute("Serviceable", "True")]
[assembly: InternalsVisibleTo("dotnet, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.DotNet.Cli.Utils.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

View file

@ -8,8 +8,8 @@
<PropertyGroup Label="Globals">
<ProjectGuid>e5ed47ef-bf25-4da9-a7fe-290c642cbf0f</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Configurer</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>

View file

@ -11,20 +11,6 @@ namespace Microsoft.DotNet.InternalAbstractions
// We should clean this up. Filed #619 to track.
public static class RuntimeEnvironmentRidExtensions
{
// Work around NuGet/Home#1941
public static IEnumerable<string> GetOverrideRestoreRuntimeIdentifiers()
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
yield return RuntimeEnvironment.GetRuntimeIdentifier();
}
else
{
yield return "win7-x86";
yield return "win7-x64";
}
}
// Gets the identfier that is used for restore by default (this is different from the actual RID, but only on Windows)
public static string GetLegacyRestoreRuntimeIdentifier()
{
@ -41,36 +27,56 @@ namespace Microsoft.DotNet.InternalAbstractions
public static IEnumerable<string> GetAllCandidateRuntimeIdentifiers()
{
return GetAllCandidateRuntimeIdentifiers(null);
}
public static IEnumerable<string> GetAllCandidateRuntimeIdentifiers(IEnumerable<string> fallbackIdentifiers = null)
{
List<string> result = new List<string>();
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
yield return RuntimeEnvironment.GetRuntimeIdentifier();
result.Add(RuntimeEnvironment.GetRuntimeIdentifier());
}
else
{
var arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal))
{
yield return "win7-" + arch;
result.Add("win7-" + arch);
}
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal))
{
yield return "win8-" + arch;
yield return "win7-" + arch;
result.Add("win8-" + arch);
result.Add("win7-" + arch);
}
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal))
{
yield return "win81-" + arch;
yield return "win8-" + arch;
yield return "win7-" + arch;
result.Add("win81-" + arch);
result.Add("win8-" + arch);
result.Add("win7-" + arch);
}
else if (RuntimeEnvironment.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal))
{
yield return "win10-" + arch;
yield return "win81-" + arch;
yield return "win8-" + arch;
yield return "win7-" + arch;
result.Add("win10-" + arch);
result.Add("win81-" + arch);
result.Add("win8-" + arch);
result.Add("win7-" + arch);
}
}
if (fallbackIdentifiers != null)
{
foreach (string fallbackIdentifier in fallbackIdentifiers)
{
if (!result.Contains(fallbackIdentifier))
{
result.Add(fallbackIdentifier);
}
}
}
return result;
}
}
}

View file

@ -209,7 +209,8 @@ namespace Microsoft.DotNet.Cli
{
HelpCommand.PrintVersionHeader();
var commitSha = GetCommitSha() ?? "N/A";
DotnetVersionFile versionFile = DotnetFiles.VersionFileObject;
var commitSha = versionFile.CommitSha ?? "N/A";
Reporter.Output.WriteLine();
Reporter.Output.WriteLine("Product Information:");
Reporter.Output.WriteLine($" Version: {Product.Version}");
@ -219,7 +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}");
Reporter.Output.WriteLine($" RID: {RuntimeEnvironment.GetRuntimeIdentifier()}");
Reporter.Output.WriteLine($" RID: {GetDisplayRid(versionFile)}");
}
private static bool IsArg(string candidate, string longName)
@ -232,16 +233,17 @@ namespace Microsoft.DotNet.Cli
return (shortName != null && candidate.Equals("-" + shortName)) || (longName != null && candidate.Equals("--" + longName));
}
private static string GetCommitSha()
private static string GetDisplayRid(DotnetVersionFile versionFile)
{
var versionFile = DotnetFiles.VersionFile;
FrameworkDependencyFile fxDepsFile = new FrameworkDependencyFile();
if (File.Exists(versionFile))
{
return File.ReadLines(versionFile).FirstOrDefault()?.Substring(0, 10);
}
string currentRid = RuntimeEnvironment.GetRuntimeIdentifier();
return null;
// 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;
}
}
}

View file

@ -2,4 +2,4 @@ using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyMetadataAttribute("Serviceable", "True")]
[assembly: InternalsVisibleTo("dotnet.Tests")]
[assembly: InternalsVisibleTo("dotnet.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

View file

@ -131,7 +131,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var rids = new List<string>();
if (string.IsNullOrEmpty(RuntimeValue))
{
return RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
return DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
}
else
{

View file

@ -425,7 +425,7 @@ namespace Microsoft.DotNet.Tools.Publish
contexts.Where(c => Equals(c.TargetFramework, framework));
var rids = string.IsNullOrEmpty(runtime) ?
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers() :
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers() :
new[] { runtime };
return contexts.Select(c => Workspace.GetRuntimeContext(c, rids));

View file

@ -11,8 +11,6 @@ namespace Microsoft.DotNet.Tools.Restore
{
public partial class RestoreCommand
{
private static readonly string DefaultRid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);

View file

@ -82,7 +82,7 @@ namespace Microsoft.DotNet.Tools.Run
.EnsureValid(Project)
.FrameworkOnlyContexts;
var rids = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
var rids = DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
ProjectContext frameworkContext;
if (Framework == null)

View file

@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Tools.Test
var projectPath = GetProjectPath(dotnetTestParams.ProjectPath);
var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ?
new[] { dotnetTestParams.Runtime } :
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
var exitCode = 0;
// Create a workspace

View file

@ -2,6 +2,7 @@
"version": "1.0.0-preview2-*",
"buildOptions": {
"emitEntryPoint": true,
"keyFile": "../../tools/Key.snk",
"embed": {
"include": [
"commands/dotnet-new/CSharp_Console.zip",

View file

@ -42,6 +42,7 @@
]
},
"buildOptions": {
"keyFile": "../../tools/Key.snk",
"copyToOutput": {
"include": [
"../../TestAssets/TestProjects/AppWithDependencyOnToolWithOutputName/**/*",