Merge pull request #1357 from dotnet/prkrishn/net451

Target net451 in ProjectModel
This commit is contained in:
Pranav K 2016-02-11 16:36:09 -08:00
commit c881516abf
20 changed files with 134 additions and 89 deletions

View file

@ -123,7 +123,11 @@ namespace Microsoft.DotNet.Cli.Utils
public ICommand EnvironmentVariable(string name, string value)
{
#if NET451
_process.StartInfo.EnvironmentVariables[name] = value;
#else
_process.StartInfo.Environment[name] = value;
#endif
return this;
}

View file

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using NuGet.Frameworks;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
@ -32,7 +32,7 @@ namespace Microsoft.DotNet.Cli.Utils
private static CommandSpec ResolveFromAppBase(string commandName, IEnumerable<string> args, bool useComSpec = false)
{
var commandPath = Env.GetCommandPathFromAppBase(AppContext.BaseDirectory, commandName);
var commandPath = Env.GetCommandPathFromAppBase(PlatformServices.Default.Application.ApplicationBasePath, commandName);
return commandPath == null
? null
: CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.BaseDirectory, useComSpec);
@ -210,7 +210,7 @@ namespace Microsoft.DotNet.Cli.Utils
CommandResolutionStrategy resolutionStrategy,
bool useComSpec = false)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows &&
Path.GetExtension(commandPath).Equals(".cmd", StringComparison.OrdinalIgnoreCase))
{
var preferredCommandPath = Env.GetCommandPath(commandName, ".exe");

View file

@ -1,17 +1,19 @@
// 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.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
public static class Constants
{
private static Platform CurrentPlatform => PlatformServices.Default.Runtime.OperatingSystemPlatform;
public static readonly string ProjectFileName = "project.json";
public static readonly string ExeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
public static readonly string ExeSuffix = CurrentPlatform == Platform.Windows ? ".exe" : string.Empty;
// Priority order of runnable suffixes to look for and run
public static readonly string[] RunnableSuffixes = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
public static readonly string[] RunnableSuffixes = CurrentPlatform == Platform.Windows
? new string[] { ".exe", ".cmd", ".bat" }
: new string[] { string.Empty };
@ -19,22 +21,23 @@ namespace Microsoft.DotNet.Cli.Utils
public static readonly string BinDirectoryName = "bin";
public static readonly string ObjDirectoryName = "obj";
public static readonly string DynamicLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so";
public static readonly string DynamicLibSuffix = CurrentPlatform == Platform.Windows ? ".dll" :
CurrentPlatform == Platform.Darwin ? ".dylib" : ".so";
public static readonly string LibCoreClrName = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "coreclr" : "libcoreclr") + DynamicLibSuffix;
public static readonly string LibCoreClrName = (CurrentPlatform == Platform.Windows ? "coreclr" : "libcoreclr") + DynamicLibSuffix;
public static readonly string RuntimeIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win7-x64" :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx.10.10-x64" : "ubuntu.14.04-x64";
public static readonly string RuntimeIdentifier = CurrentPlatform == Platform.Windows ? "win7-x64" :
CurrentPlatform == Platform.Darwin ? "osx.10.10-x64" : "ubuntu.14.04-x64";
public static readonly string StaticLibSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".lib" : ".a" ;
public static readonly string StaticLibSuffix = CurrentPlatform == Platform.Windows ? ".lib" : ".a";
public static readonly string ResponseFileSuffix = ".rsp";
public static readonly string HostExecutableName = "corehost" + ExeSuffix;
public static readonly string[] HostBinaryNames = new string[] {
HostExecutableName,
(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "hostpolicy" : "libhostpolicy") + DynamicLibSuffix
(CurrentPlatform == Platform.Windows ? "hostpolicy" : "libhostpolicy") + DynamicLibSuffix
};
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.IO;
using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -12,7 +11,7 @@ namespace Microsoft.DotNet.Cli.Utils
/// <summary>
/// Gets the path to the version of corehost that was shipped with this command
/// </summary>
public static string LocalHostExePath => Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
public static string LocalHostExePath => Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, Constants.HostExecutableName);
public static string HostExePath
{

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -18,7 +19,7 @@ namespace Microsoft.DotNet.Cli.Utils
if (_executableExtensions == null)
{
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
_executableExtensions = PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows
? Environment.GetEnvironmentVariable("PATHEXT")
.Split(';')
.Select(e => e.ToLower().Trim('"'))
@ -35,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Utils
{
if (_searchPaths == null)
{
var searchPaths = new List<string> {AppContext.BaseDirectory};
var searchPaths = new List<string> { PlatformServices.Default.Application.ApplicationBasePath };
searchPaths.AddRange(Environment
.GetEnvironmentVariable("PATH")

View file

@ -3,7 +3,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Common
{
@ -98,7 +98,7 @@ namespace Microsoft.DotNet.Tools.Common
}
StringComparison compare;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume
@ -216,7 +216,7 @@ namespace Microsoft.DotNet.Tools.Common
{
var comparison = StringComparison.Ordinal;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
comparison = StringComparison.OrdinalIgnoreCase;
}

View file

@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Cli.Utils
public static Reporter Create(Func<bool, AnsiConsole> getter)
{
return new Reporter(getter(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)));
return new Reporter(getter(PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows));
}
public void WriteLine(string message)

View file

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils.CommandParsing;
using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Utils
{
@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Cli.Utils
var useComSpec = false;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
// Only forward slashes are used in script blocks. Replace with backslashes to correctly
// locate the script. The directory separator is platform-specific.

View file

@ -13,7 +13,6 @@ namespace Microsoft.DotNet.Cli.Utils
private StringBuilder _builder;
private StringWriter _capture;
private Action<string> _write;
private Action<string> _writeLine;
public string CapturedOutput

View file

@ -2,19 +2,23 @@
"version": "1.0.0-*",
"compilationOptions": {
"keyFile": "../../tools/Key.snk"
"keyFile": "../../tools/Key.snk",
"warningsAsErrors": true
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"System.Reflection.Metadata": "1.2.0-rc2-23811",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537"
},
"frameworks": {
"net451": { },
"dnxcore50": {
"imports": "portable-net45+win8"
"imports": "portable-net45+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811"
}
}
},

View file

@ -58,7 +58,7 @@ namespace Microsoft.DotNet.ProjectModel
}
private static bool EnumerableEquals(IEnumerable<string> left, IEnumerable<string> right)
=> Enumerable.SequenceEqual(left ?? Array.Empty<string>(), right ?? Array.Empty<string>());
=> Enumerable.SequenceEqual(left ?? EmptyArray<string>.Value, right ?? EmptyArray<string>.Value);
public override int GetHashCode()
{
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.ProjectModel
{
if (@new != null)
{
old = old ?? Array.Empty<string>();
old = old ?? EmptyArray<string>.Value;
return old.Concat(@new).Distinct().ToArray();
}
return old;

View file

@ -162,7 +162,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
var analyzers = GetAnalyzerReferences(package);
return new LibraryExport(package, compileAssemblies,
sourceReferences, runtimeAssemblies, Array.Empty<LibraryAsset>(), nativeLibraries, analyzers);
sourceReferences, runtimeAssemblies, EmptyArray<LibraryAsset>.Value, nativeLibraries, analyzers);
}
private LibraryExport ExportProject(ProjectDescription project)
@ -175,8 +175,8 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
sourceReferences: Enumerable.Empty<string>(),
nativeLibraries: Enumerable.Empty<LibraryAsset>(),
runtimeAssets: Enumerable.Empty<LibraryAsset>(),
runtimeAssemblies: Array.Empty<LibraryAsset>(),
analyzers: Array.Empty<AnalyzerReference>());
runtimeAssemblies: EmptyArray<LibraryAsset>.Value,
analyzers: EmptyArray<AnalyzerReference>.Value);
}
var compileAssemblies = new List<LibraryAsset>();
@ -226,7 +226,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
// just the same as compileAssemblies and nativeLibraries are empty
// Also no support for analyzer projects
return new LibraryExport(project, compileAssemblies, sourceReferences,
compileAssemblies, runtimeAssets, Array.Empty<LibraryAsset>(), Array.Empty<AnalyzerReference>());
compileAssemblies, runtimeAssets, EmptyArray<LibraryAsset>.Value, EmptyArray<AnalyzerReference>.Value);
}
private static string ResolvePath(Project project, string configuration, string path)
@ -250,13 +250,13 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
return new LibraryExport(
library,
string.IsNullOrEmpty(library.Path) ?
Array.Empty<LibraryAsset>() :
EmptyArray<LibraryAsset>.Value :
new[] { new LibraryAsset(library.Identity.Name, library.Path, library.Path) },
Array.Empty<string>(),
Array.Empty<LibraryAsset>(),
Array.Empty<LibraryAsset>(),
Array.Empty<LibraryAsset>(),
Array.Empty<AnalyzerReference>());
EmptyArray<string>.Value,
EmptyArray<LibraryAsset>.Value,
EmptyArray<LibraryAsset>.Value,
EmptyArray<LibraryAsset>.Value,
EmptyArray<AnalyzerReference>.Value);
}
private IEnumerable<string> GetSharedSources(PackageDescription package)

View file

@ -1,5 +1,5 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.ProjectModel
{
@ -11,13 +11,19 @@ namespace Microsoft.DotNet.ProjectModel
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return Windows; }
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { return Linux; }
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return OSX; }
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
{
case Platform.Windows:
return Windows;
case Platform.Darwin:
return OSX;
case Platform.Linux:
return Linux;
default:
throw new InvalidOperationException("Unknown Platform");
}
}
}
public static PlatformFileNameSuffixes DotNet { get; } = new PlatformFileNameSuffixes
{

View file

@ -0,0 +1,14 @@
// 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.
namespace Microsoft.DotNet.ProjectModel
{
internal static class EmptyArray<T>
{
#if NET451
public static readonly T[] Value = new T[0];
#else
public static readonly T[] Value = System.Array.Empty<T>();
#endif
}
}

View file

@ -144,9 +144,9 @@ namespace Microsoft.DotNet.ProjectModel
project.CompilerName = rawProject.ValueAsString("compilerName");
project.TestRunner = rawProject.ValueAsString("testRunner");
project.Authors = rawProject.ValueAsStringArray("authors") ?? Array.Empty<string>();
project.Owners = rawProject.ValueAsStringArray("owners") ?? Array.Empty<string>();
project.Tags = rawProject.ValueAsStringArray("tags") ?? Array.Empty<string>();
project.Authors = rawProject.ValueAsStringArray("authors") ?? EmptyArray<string>.Value;
project.Owners = rawProject.ValueAsStringArray("owners") ?? EmptyArray<string>.Value;
project.Tags = rawProject.ValueAsStringArray("tags") ?? EmptyArray<string>.Value;
project.Language = rawProject.ValueAsString("language");
project.ReleaseNotes = rawProject.ValueAsString("releaseNotes");

View file

@ -5,10 +5,10 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Xml.Linq;
using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Resolution
@ -60,7 +60,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
return referenceAssembliesPath;
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform != Platform.Windows)
{
// There is no reference assemblies path outside of windows
// The environment variable can be used to specify one

View file

@ -3,7 +3,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.ProjectModel.Utilities
{
@ -84,7 +84,7 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
}
StringComparison compare;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume

View file

@ -1,7 +1,10 @@
// 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.
#if !NET451
using System.Runtime.Loader;
#endif
using System.Reflection;
using System.Text;
using NuGet.Versioning;
@ -16,7 +19,11 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
internal static NuGetVersion GetAssemblyVersion(string path)
{
#if NET451
return new NuGetVersion(AssemblyName.GetAssemblyName(path).Version);
#else
return new NuGetVersion(AssemblyLoadContext.GetAssemblyName(path).Version);
#endif
}
public static string RenderVersion(VersionRange range)

View file

@ -5,15 +5,9 @@
},
"description": "Types to model a .NET Project",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"System.Reflection.Metadata": "1.2.0-rc2-23811",
"System.Runtime.Loader": "4.0.0-rc2-23811",
"System.Dynamic.Runtime": "4.0.11-rc2-23811",
"System.Security.Cryptography.Algorithms": "4.0.0-rc2-23811",
"Microsoft.CSharp": "4.0.1-rc2-23811",
"System.Xml.XDocument": "4.0.11-rc2-23811",
"NuGet.Packaging": "3.4.0-beta-583",
"NuGet.Packaging": "3.4.0-beta-583",
"Microsoft.Extensions.FileSystemGlobbing": "1.0.0-rc2-15996",
"Microsoft.Extensions.JsonParser.Sources": {
"type": "build",
@ -28,10 +22,22 @@
"version": "1.0.0-*"
}
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.IO": ""
}
},
"dnxcore50": {
"imports": "portable-net45+win8"
"imports": "portable-net45+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"System.Dynamic.Runtime": "4.0.11-rc2-23811",
"System.Runtime.Loader": "4.0.0-rc2-23811",
"System.Security.Cryptography.Algorithms": "4.0.0-rc2-23811",
"Microsoft.CSharp": "4.0.1-rc2-23811",
"System.Xml.XDocument": "4.0.11-rc2-23811"
}
}
},
"scripts": {

View file

@ -12,16 +12,18 @@
"dependencies": {
"Newtonsoft.Json": "7.0.1",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-16040",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-16040"
},
"frameworks": {
"net451": { },
"dnxcore50": {
"imports": "portable-net45+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"System.Resources.ResourceManager": "4.0.1-rc2-23811",
"System.Runtime.Serialization.Primitives": "4.1.0-rc2-23811"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
}
},
"scripts": {
}
"scripts": { }
}