Move all CLI libraries to be single-TFM targeting netstandard1.3 where possible.

Microsoft.Extensions.Testing.Abstractions is the only one I couldn't move to netstandard1.3 that should be.  But this library should be removed with the new `dotnet test` strategy.
This commit is contained in:
Eric Erhardt 2016-09-22 18:34:24 -05:00
parent 2727b191e3
commit eec324a844
21 changed files with 70 additions and 104 deletions

View file

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

View file

@ -142,8 +142,7 @@ namespace Microsoft.DotNet.Cli.Utils
return ProjectContext.Create(
projectRootPath,
framework,
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers());
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
}
private IEnumerable<string> GetAllowedCommandExtensionsFromEnvironment(IEnvironmentProvider environment)

View file

@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.Utils
{
internal static class DotnetRuntimeIdentifiers
{
public static IEnumerable<string> InferCurrentRuntimeIdentifiers()
public static IEnumerable<string> InferCurrentRuntimeIdentifiers(DotnetVersionFile versionFile)
{
IEnumerable<string> fallbackIdentifiers = null;
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Cli.Utils
FrameworkDependencyFile fxDepsFile = new FrameworkDependencyFile();
if (!fxDepsFile.SupportsCurrentRuntime())
{
string buildRid = DotnetFiles.VersionFileObject.BuildRid;
string buildRid = versionFile.BuildRid;
if (!string.IsNullOrEmpty(buildRid))
{
fallbackIdentifiers = new string[] { buildRid };

View file

@ -15,14 +15,7 @@
"NuGet.ProjectModel": "3.6.0-rc-1954"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
}
}
},
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50"
],

View file

@ -17,26 +17,7 @@
"NuGet.ProjectModel": "3.6.0-rc-1954"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
},
"System.Collections": {
"type": "build"
},
"System.IO": {
"type": "build"
},
"System.Threading.Tasks": {
"type": "build"
},
"System.Text.Encoding": {
"type": "build"
}
}
},
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50"
]

View file

@ -1,7 +1,8 @@
// 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 Microsoft.DotNet.Cli.Utils;
using System;
using System.IO;
using Microsoft.DotNet.Archive;
using Microsoft.Extensions.EnvironmentAbstractions;
@ -11,8 +12,9 @@ namespace Microsoft.DotNet.Configurer
{
private ITemporaryDirectory _temporaryDirectory;
public string NuGetPackagesArchive => DotnetFiles.NuGetPackagesArchive;
public string NuGetPackagesArchive =>
Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "nuGetPackagesArchive.lzma"));
public NuGetPackagesArchiver() : this(FileSystemWrapper.Default.Directory)
{
}

View file

@ -14,20 +14,7 @@
"System.Linq.Expressions": "4.1.0"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
},
"System.Collections": {
"type": "build"
},
"System.IO": {
"type": "build"
}
}
},
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50"
]

View file

@ -7,7 +7,6 @@
"allowUnsafe": true
},
"frameworks": {
"net451": {},
"netstandard1.3": {
"dependencies": {
"System.AppContext": "4.1.0",

View file

@ -14,20 +14,7 @@
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
},
"System.Collections": {
"type": "build"
},
"System.IO": {
"type": "build"
}
}
},
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50",
"portable-net45+win8"

View file

@ -2,7 +2,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !NET451
using System.Runtime.Loader;
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
#endif
using System.Reflection;
using System.Text;
@ -22,10 +25,42 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
#if NET451
return new NuGetVersion(AssemblyName.GetAssemblyName(path).Version);
#else
return new NuGetVersion(AssemblyLoadContext.GetAssemblyName(path).Version);
return new NuGetVersion(GetAssemblyVersionPrivate(path));
#endif
}
#if !NET451
private static Version GetAssemblyVersionPrivate(string assemblyPath)
{
using (var fileStream = new FileStream(assemblyPath, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read))
{
return GetAssemblyVersionPrivate(fileStream);
}
}
private static Version GetAssemblyVersionPrivate(Stream assemblyStream)
{
Version result = null;
try
{
using (PEReader peReader = new PEReader(assemblyStream, PEStreamOptions.LeaveOpen))
{
if (peReader.HasMetadata)
{
MetadataReader reader = peReader.GetMetadataReader();
result = reader.GetAssemblyDefinition().Version;
}
}
}
catch (BadImageFormatException)
{
// not a PE
}
return result;
}
#endif
public static string RenderVersion(VersionRange range)
{
if (range == null)
@ -50,7 +85,7 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
// Work around nuget bug: https://github.com/NuGet/Home/issues/1598
// sb.AppendFormat("{0}-*", range.MinVersion);
sb.Append($"{range.MinVersion.Version.Major}.{range.MinVersion.Version.Minor}.{range.MinVersion.Version.Build}");
if (string.IsNullOrEmpty(range.MinVersion.Release) ||
if (string.IsNullOrEmpty(range.MinVersion.Release) ||
string.Equals("-", range.MinVersion.Release))
{
sb.Append($"-*");

View file

@ -15,20 +15,7 @@
"System.Reflection.Metadata": "1.4.1-beta-24410-02"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build"
},
"System.Collections": {
"type": "build"
},
"System.IO": {
"type": "build"
}
}
},
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50",
"dotnet5.4"
@ -36,7 +23,6 @@
"dependencies": {
"Microsoft.CSharp": "4.0.1",
"System.Dynamic.Runtime": "4.0.11",
"System.Runtime.Loader": "4.0.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"System.Security.Cryptography.Algorithms": "4.2.0",
"System.Threading.Thread": "4.0.0",

View file

@ -10,12 +10,11 @@
}
},
"frameworks": {
"netstandard1.6": {
"netstandard1.3": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50"
]
},
"net451": {}
}
},
"packOptions": {
"projectUrl": "",

View file

@ -3,9 +3,10 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using System.Linq;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Test
@ -27,7 +28,7 @@ namespace Microsoft.DotNet.Tools.Test
var projectPath = GetProjectPath(dotnetTestParams.ProjectOrAssemblyPath);
var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime)
? new[] {dotnetTestParams.Runtime}
: DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
: DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers(DotnetFiles.VersionFileObject);
var exitCode = 0;
// Create a workspace

View file

@ -5,7 +5,8 @@
"compile": {
"include": [
"**/*.cs",
"../dotnet/CommandLine/*.cs"
"../dotnet/CommandLine/*.cs",
"../dotnet/DotnetFiles.cs"
]
}
},

View file

@ -11,11 +11,7 @@ namespace Microsoft.Extensions.Testing.Abstractions
{
internal static int GetMethodToken(this MethodInfo methodInfo)
{
#if NETSTANDARD1_3
var methodToken = methodInfo.GetMetadataToken();
#else
var methodToken = methodInfo.MetadataToken;
#endif
return methodToken;
}

View file

@ -16,8 +16,7 @@
"System.Reflection.Metadata": "1.4.1-beta-24426-02"
},
"frameworks": {
"net451": {},
"netstandard1.6": {
"netstandard1.5": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50",
"portable-net45+win8"

View file

@ -4,11 +4,12 @@
using System;
using System.IO;
using System.Reflection;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
namespace Microsoft.DotNet.Cli
{
public static class DotnetFiles
internal static class DotnetFiles
{
private static string SdkRootFolder => Path.Combine(typeof(DotnetFiles).GetTypeInfo().Assembly.Location, "..");
@ -25,9 +26,6 @@ namespace Microsoft.DotNet.Cli.Utils
get { return s_versionFileObject.Value; }
}
public static string NuGetPackagesArchive =>
Path.GetFullPath(Path.Combine(SdkRootFolder, "nuGetPackagesArchive.lzma"));
/// <summary>
/// Reads the version file and adds runtime specific information
/// </summary>

View file

@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
@ -131,7 +132,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var rids = new List<string>();
if (string.IsNullOrEmpty(RuntimeValue))
{
return DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
return DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers(DotnetFiles.VersionFileObject);
}
else
{

View file

@ -5,8 +5,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Compiler;
namespace Microsoft.DotNet.Tools.Build

View file

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Files;
@ -414,7 +415,7 @@ namespace Microsoft.DotNet.Tools.Publish
contexts.Where(c => Equals(c.TargetFramework, framework));
var rids = string.IsNullOrEmpty(runtime) ?
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers() :
DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers(DotnetFiles.VersionFileObject) :
new[] { runtime };
return contexts.Select(c => Workspace.GetRuntimeContext(c, rids));

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
@ -83,7 +84,7 @@ namespace Microsoft.DotNet.Tools.Run
.EnsureValid(Project)
.FrameworkOnlyContexts;
var rids = DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers();
var rids = DotnetRuntimeIdentifiers.InferCurrentRuntimeIdentifiers(DotnetFiles.VersionFileObject);
ProjectContext frameworkContext;
if (Framework == null)